使用JSoup从Google搜索结果的所有页面中检索所有链接

时间:2015-02-17 18:27:50

标签: java html-parsing jsoup

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

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"));
  } 

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

1 个答案:

答案 0 :(得分:3)

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

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