Get Google Search Images using php
You could use the PHP Simple HTML DOM library for this:
<?php include "simple_html_dom.php"; $search_query = "ENTER YOUR SEARCH QUERY HERE"; $search_query = urlencode( $search_query ); $html = file_get_html( "https://www.google.com/search?q=$search_query&tbm=isch" ); $image_container = $html->find('div#rcnt', 0); $images = $image_container->find('img'); $image_count = 10; //Enter the amount of images to be shown $i = 0; foreach($images as $image){ if($i == $image_count) break; $i++; // DO with the image whatever you want here (the image element is '$image'): echo $image; }
This will print a specific number of images (number is set in '$image_count').
For more information on the PHP Simple HTML DOM library click here.
i am not very much sure about this ,but still google gives a nice documentation about this.
$url = "https://ajax.googleapis.com/ajax/services/search/images?" . "v=1.0&q=barack%20obama&userip=INSERT-USER-IP"; // sendRequest// note how referer is set manually$ch = curl_init();curl_setopt($ch, CURLOPT_URL, $url);curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);curl_setopt($ch, CURLOPT_REFERER, /* Enter the URL of your site here */);$body = curl_exec($ch);curl_close($ch);// now, process the JSON string$json = json_decode($body);// now have some fun with the results...
this is from the official Google's developer guide regarding image searching.for more reference you can have a reference of the same here.
https://developers.google.com/image-search/v1/jsondevguide#json_snippets_php
in $url you must set the search keywords.