使用JSoup从Google搜索结果的所有页面中检索所有链接 [英] Retrieving all links from all pages of Google search result using JSoup

查看:182
本文介绍了使用JSoup从Google搜索结果的所有页面中检索所有链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下代码在java中使用JSoup解析HTML。

I have the following code for parsing HTML in java using JSoup.

Document linksDoc = null; 
linksDoc = Jsoup.connect("http://www.google.com/search?q=jbutton").userAgent("Mozilla").get();
Elements titles = linksDoc.select("h3.r > a");

for(Element e: titles){
    System.out.println("text"+cnt+": " +e.attr("href"));
  } 

问题是我只能检索首页搜索结果链接。如何从谷歌搜索结果的其余页面获取链接。

The problem is that i am able to retrieve only first page search result links. What should i do to get the links from rest of the pages of google search results.

推荐答案

添加如果您想从第二页获得结果,请将& start = 10 添加到网址。对于第三页使用& start = 20 等等。

Add &start=10 to URL if you want to get results from second page. For third page use &start=20 and so on.

Document linksDoc = Jsoup.connect("http://www.google.com/search?q=jbutton&start=10")
        .userAgent("Mozilla").get();
//...

这篇关于使用JSoup从Google搜索结果的所有页面中检索所有链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆