Use curl for collection, $ url & #039; kakaku. compc & #039; how can I modify the following code? {Code...} is collected using curl. $ url = 'HTTP: // kakaku.com/pc/'??
function GetContent($url = "", $post_data = '', $method = 'POST', $timeout = 500) { if (is_array($post_data)) { $post_data = http_build_query($post_data); } if ($method == 'GET') { $url = $url . '?' . ltrim($post_data, '?'); } $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HTTPHEADER, array('User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US) \r\n Accept: */*')); curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); if ($method == 'POST') { curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); } $content = curl_exec($ch); $response = curl_getinfo($ch); return $content; }
Reply content:
Use curl to collect data. For $ url = 'HTTP: // kakaku.com/pc/'?, can I modify the following code?
function GetContent($url = "", $post_data = '', $method = 'POST', $timeout = 500) { if (is_array($post_data)) { $post_data = http_build_query($post_data); } if ($method == 'GET') { $url = $url . '?' . ltrim($post_data, '?'); } $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HTTPHEADER, array('User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US) \r\n Accept: */*')); curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); if ($method == 'POST') { curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); } $content = curl_exec($ch); $response = curl_getinfo($ch); return $content; }
The value of the third parameter isGET
You can.
Do you want to collect the get or post request content?
Directly collect the homepage
echo file_get_contents('http://kakaku.com/pc/');
You can.