Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get ALL google search results using api [duplicate]

Tags:

I need to get google search results for query. But using something like this

$query = 'Nikita Platonenko'; $url = "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=".urlencode($query); $body = file_get_contents($url); $json = json_decode($body); var_dump($json) 

i get only 4 results, I've already read about google ajax search but couldn't understand it. Please advise how to get all resulsts, or just first 100 results?

like image 256
user1279525 Avatar asked Dec 27 '12 13:12

user1279525


People also ask

How do I get more than 10 results on Google API?

IF YOU ARE USING THE API Google Custom Search and Google Site Search return up to 10 results per query. If you want to display more than 10 results to the user, you can issue multiple requests (using the start=0, start=11 … parameters) and display the results on a single page.

Is there an API for Google search results?

Google Search APIs are interfaces that allow you to extract google search results. The best google search APIs often let you build websites and programs to let you access SERPs (Search Engine Results Pages). One can use these APIs to retrieve search results for specific parameters, depending upon the user's wish.


1 Answers

<?php $query = 'Nikita%20Platonenko'; $url = "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=".$query;  $body = file_get_contents($url); $json = json_decode($body);  for($x=0;$x<count($json->responseData->results);$x++){  echo "<b>Result ".($x+1)."</b>"; echo "<br>URL: "; echo $json->responseData->results[$x]->url; echo "<br>VisibleURL: "; echo $json->responseData->results[$x]->visibleUrl; echo "<br>Title: "; echo $json->responseData->results[$x]->title; echo "<br>Content: "; echo $json->responseData->results[$x]->content; echo "<br><br>";  }  ?> 

As the AJAX Api is now depreciated, you can use a third party service like SerpApi to get Google results. They have a GitHub repository, and it should be easy to integrate:

$query = [     "q" => "Coffee",     "google_domain" => "google.com", ];  $serp = new GoogleSearchResults(); $json_results = $serp.json($query); 
like image 142
Monchito Avatar answered Oct 15 '22 11:10

Monchito