get number of google search results

java, search

Solution

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))

Problem

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?

Original source