I can get the source code of the search result page. So my question is about how to get MORE. For google, it only shows the first 20 image results in the source code I get, for Yahoo it's about 50. Because in both cases real people need to scroll down the page to see more search result.
Question: Is there anyway the script can do the "scroll down" for me so I can get more results?
The code I'm using:
require_once('simple_html_dom.php');
$url = "https://www.google.com/search?tbm=isch&q=cool+image";
$html = file_get_html($url);
foreach($html->find('img') as $element) {
$image_url = $element->src;
echo $image_url, "<br />";}
I'll answer my own question. - -|||
Google actually keeps the old version. To use that version, first search something, then scroll to the bottom and click "Switch to basic version".
Now only 20 images are displayed on each page and the url contains page parameters.
Because it's displaying 20 images each page, the second page's url has the parameter:
start=20
and the third page will be
start=40
This parameter: sout=1 is needed in the url to tell google you want the basic version.
To conclude, the simplest google image search url with page number would be:
$url = "https://www.google.com/search?tbm=isch&sout=1&start=" . ($pageNum -1)*20. "&q=" . $key_word ;