Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get number of google search results

Tags:

java

search

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?

like image 302
user1532714 Avatar asked Jul 19 '12 21:07

user1532714


1 Answers

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))
like image 196
Jan Gerlinger Avatar answered Nov 09 '22 16:11

Jan Gerlinger