Get Google Search images using php

Search Google images with car keywords and get car images.

enter image description here

I found two links for implementation as follows:

but he gave 4 random images of nothing more. enter image description hereenter image description hereenter image description hereenter image description here

Question: How to get car images in PHP using the keyword that I want to implement, as we search in Google?

Any suggestion would be appreciated!

+4
source share
3 answers

You can use the PHP Simple HTML DOM library to do 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 certain number of images (the number is set to '$ image_count').

For more information on the simple PHP DOM HTML library, click here.

+5
source

I am not very sure about this, but google still gives good 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 image search guide. for more information you can have a link to the same here.

  https://developers.google.com/image-search/v1/jsondevguide#json_snippets_php 

in $ url you must set the search keywords.

+1
source

I donโ€™t know if this will work for you, but you can try a technique called webpage clipping. Find out more in this question:

PHP Web Scraper

0
source

Source: https://habr.com/ru/post/1479877/


All Articles