I searched a lot to retrieve the number of search results in google using java, but nothing worked. I have tried Google Custom Search API aswell. I don't want the title/url of results, just number of total results found. Can some one please guide me?
Asked
Active
Viewed 9,534 times
5
-
See this answer: http://stackoverflow.com/a/34808872/363573 – Stephan Jan 15 '16 at 10:25
1 Answers
13
By using the Custom Search API, you're on the right way.
There's a totalResults
key in the response JSON that you get from your query. Just grab it's value and you're done.
If you want your JSON to only contain that value, add the fields
parameter to your query like that:
https://www.googleapis.com/customsearch/v1?key={YOUR_API_KEY}&cx={YOUR_SEARCH_ENGINE_ID}
&q={YOUR_SEARCH_STRING}&alt=json&fields=queries(request(totalResults))

Jan Gerlinger
- 7,361
- 1
- 44
- 52
-
1Here is a solution not relying on Custom Search API: http://stackoverflow.com/a/34808872/363573 – Stephan Jan 15 '16 at 10:26
-
Note that the Custom Search API only allows you 100 free searches a day (and I imagine the other commented solution will throttle you similarly). – Chris Jones Dec 24 '19 at 20:30
-
@Stephan Google may start banning your queries after couple of searches as they have better protection system against bots. – Ammad Khalid Jul 12 '20 at 11:16