Skip to content Skip to sidebar Skip to footer

How To Get #resultstats From Google Using Jsoup

I am trying to get the number of articles that Google shows us: This is a Google search of jeb bush barack obama, and it shows the number that I need, which is the 10,200,000 artic

Solution 1:

Actually, you may be getting some optimized javascript code (for modern browsers) that need to be run to see actual results stats. Instead, change your user agent string (for a oldest browser UA string) and the url like in the code below:

DEMO

http://try.jsoup.org/~iYErM3BgfjILVJZshDMkAd-XQCk

SAMPLE CODE

String url = "https://www.google.com/search?q=jeb+bush+barack+obama";

Document document = Jsoup //
                   .connect(url) //
                   .userAgent("Mozilla/5.0 (Windows; U; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)") //
                   .get();

Element divResultStats = document.select("div#resultStats").first();
if (divResultStats==null) {
    thrownew RuntimeException("Unable to find results stats.");
}

System.out.println(divResultStats.text());

OUTPUT (as of this writing...)

About 10,500,000 results

Tested on Jsoup 1.8.3

More UA Strings: http://www.useragentstring.com/

Post a Comment for "How To Get #resultstats From Google Using Jsoup"