gpt4 book ai didi

java - Jaunt 网络爬虫 - 无法访问 Google 搜索结果的下一页

转载 作者:行者123 更新时间:2023-11-30 08:03:46 24 4
gpt4 key购买 nike

import com.jaunt.*;
public class JauntCrawler{
public static void main(String[] args){
try{
UserAgent userAgent = new UserAgent(); //create new userAgent (headless browser)
userAgent.visit("http://google.de"); //visit google
userAgent.doc.apply("schmetterlinge"); //apply form input (starting at first editable field)
userAgent.doc.submit(); //click submit button labelled "Google Search"


Elements links = userAgent.doc.findEvery("<h3 class=r>").findEvery("<a>"); //find search result links
for(Element link : links) System.out.println(link.getAt("href")); //print results

if(userAgent.doc.nextPageLinkExists()) {
userAgent.visit(userAgent.doc.nextPageLink().getHref());
Elements newlinks = userAgent.doc.findEvery("<h3 class=r>").findEvery("<a>");
System.out.println("\nPage 2:");
for(Element link : newlinks) System.out.println(link.getAt("href"));
}
}
catch(JauntException e){ //if an HTTP/connection error occurs, handle JauntException.
System.err.println(e);
}
}
}

我希望从 Google 返回更多搜索结果,而不仅仅是首页。因此第二个 for 循环基本上应该返回下一页的结果,但事实并非如此。知道为什么吗?

最佳答案

我也遇到了同样的问题。用户代理不会进入下一页,但我找到了另一种方法来实现此目的:

Elements nextLinks = userAgent.doc.findEvery("<a class=fl");
for(int i=0;i<nextLinks.size();i++) {
userAgent.visit("http://google.co.in/search?q="+<search_string+"&start="+(i+1)*10);
links = userAgent.doc.findEvery("<h3 class=r>").findEvery("<a>");
for(Element link : links) System.out.println(link.getAt("href"));
}

关于java - Jaunt 网络爬虫 - 无法访问 Google 搜索结果的下一页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31479473/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com