Hi Allen,
Ik probeer een site te scrapen, maar ik krijg telkens een response van de server dat mn cookies niet aanstaan.
Dmv curl zou je cookies kunnen simuleren.
Zie onderstaande code. Doe ik iets fout?
<?php ini_set('display_startup_errors',1);
ini_set('display_errors',1);
//ome/scraper/domains/scraper.nl/public_html
$ch = curl_init(); // initiate curl+
$agent= 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322)';
$url = "site_to_spider"; // where you want to post data
$cookie_file = '/home/scraper/domains/scraper.nl/public_html/cookies.txt';
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt ($ch,CURLOPT_COOKIEJAR, $cookie_file);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
curl_setopt($ch, CURLOPT_COOKIE, "");
curl_setopt($ch, CURLOPT_POSTFIELDS, "id=53421d01dda9f&key=242B424A22412B214B434122252A2C254B232C42424341444B2243204321214B"); // define what you want to post
$output = curl_exec ($ch); // execute
curl_close ($ch); // close curl handle
echo $output;
?>
1.564 views