KontrCode
KontrCode

Reputation: 89

JSOUP - Getting pages and links from Google

I am able to retrieve URLs and Titles from Google using Jsoup only from the first page. What I want to do is to retrieve data from all pages or from a specific page. My code is as follows:

google  = "http://www.google.com/search?q=" + searchString + "&num=20";
String charset = "UTF-8";
String userAgent = "ExampleBot 1.0 (+http://example.com/bot)";

Elements links = Jsoup.connect(google + URLEncoder.encode(searchString, charset))
    .userAgent(userAgent).get().select(".g>.r>a"); 

According to this example, I should be able to pick specific page changing &num=20 with &start=30 but it is not working. Also changing &num=20 with something like &num=30 or &num=40 doesn't affect my result set at all. Can someone show me where I go wrong?

Help will be appreciated.

Upvotes: 0

Views: 121

Answers (1)

Luk
Luk

Reputation: 2246

num parameter defines how many links will be shown on the webpage.

start defines from which result to start.

So for example https://www.google.pl/search?q=jsoup&num=5&start=120 will show results from 120-125.

Try it with your browser

Upvotes: 1

Related Questions