簡體   English   中英

使用JSoup從Google搜索結果的所有頁面檢索所有鏈接

[英]Retrieving all links from all pages of Google search result using JSoup

我有以下代碼,用於使用JSoup在Java中解析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"));
  } 

問題是我只能檢索首頁搜索結果鏈接。 我應該怎么做才能從Google搜索結果的其余頁面獲得鏈接。

如果要從第二頁獲取結果,請在URL上添加&start=10 對於第三頁,使用&start=20 ,依此類推。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM