This question already has an answer here:
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?
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:
The answer:
Here is what I use successfully:
I don't think you have full control over how many results that can be obtained in the query. But you can control the results size (
rsz=large
), and where it starts.Other notes:
In addition, it is always good to include the user's ip address there. Because, Google limits the number of queries based unique ip addresses (meaning, how many from an ip address). So if they are all coming from your server, you will be limited in how many queries you can send, but the limits go way down if you send the user's ip address. In addition, caching the results for a couple of days is an added bonus.