I would like a tips about how to force this script to interpret the google url as if i’d done the research on google
<?php
$ch = curl_init();
$timeout = 5;
curl_setopt ($ch, CURLOPT_URL, 'http://www.google.com/?q=cr#hl=fr&q=help+me+please&psj=1&oq=variable+get+google+recherche&fp=1/');
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$file_contents = curl_exec($ch);
curl_close($ch);
$lines = array();
$lines = explode("\n", $file_contents);
foreach($lines as $line_num => $line) {
echo "Line # {$line_num} : ".htmlspecialchars($line)."<br />\n";
}
?>
This is what I’ve come with, but when I try this on my server I only get google.com source code and not the source code from the google page after the research.
Can anyone help me ? thanks 😀
This isn’t the best way you could be doing this.
The JSON/Atom custom search API will do what you want. http://code.google.com/apis/customsearch/v1/overview.html
For Yahoo, the BOSS API: http://developer.yahoo.com/search/boss/
And for Bing: http://www.bing.com/toolbox/bingdeveloper/
Additionally, the reason your CURL isn’t giving you the results you need is because the search query is behind a hash in the URL. That means Google is pulling the results in via ajax. You will have to find a way to directly pass the query string to the google results page.
You can attempt to simulate this by turning javascript off in your browser, performing a search, and copying the resulting URL.
For the lazy, this is: http://www.google.com/search?hl=en&q=test+search