Java 从使用无限滚动的网页解析html
我想从使用无限滚动的网页中解析html,例如:pinterest.com,以便获取所有项目Java 从使用无限滚动的网页解析html,java,jsoup,Java,Jsoup,我想从使用无限滚动的网页中解析html,例如:pinterest.com,以便获取所有项目 public List<String> popularTagsPinterest(String tag) throws Exception { List<String> results = new ArrayList<>(); try { Document doc = Jsoup.connect( url
public List<String> popularTagsPinterest(String tag) throws Exception {
List<String> results = new ArrayList<>();
try {
Document doc = Jsoup.connect(
urlPinterest + tag + "&eq=%23" + tag + "&etslf=6622&term_meta[]=%23" + tag + "%7Cautocomplete%7C0")
.timeout(90000).get();
Elements img1 = doc.select("a.pinImageWrapper img.pinImg");
for (Element e : img1) {
results.add(e.attr("src"));
System.out.println(e.attr("src"));
}
} catch (Exception e) {
e.printStackTrace();
}
return results;
}
public List popularTagsPinterest(字符串标记)引发异常{
列表结果=新建ArrayList();
试一试{
Document doc=Jsoup.connect(
urlPinterest+tag+“&eq=%23”+tag+“&etslf=6622&term\u meta[]=%23”+tag+%7Cautocomplete%7C0”)
.timeout(90000.get();
元素img1=doc.select(“a.pinImageWrapper img.pinImg”);
用于(元素e:img1){
结果:添加(e.attr(“src”);
System.out.println(e.attr(“src”);
}
}捕获(例外e){
e、 printStackTrace();
}
返回结果;
}
获取基本url和加载另一个部件的ajax调用即可
查看此页,这是一个很好的示例
获取基本url和加载另一个部件的ajax调用即可 查看此页,这是一个很好的示例
使用javascript加载Jsoup内容的网页无法获取所有元素。您需要执行javascript代码并模拟浏览器滚动以使其加载所有元素,这是解析器无法做到的。有一个API可以启动本地浏览器并模拟滚动(如果您愿意,可以无限次)。我只是不记得名字了……我相信jsoup有一个执行脚本method@BackSlash,我需要更多的信息。注意:我正在使用angular-in-front-endLook进入无头浏览器,并支持js:HtmlUnit、phantomjs等。使用javascript加载Jsoup内容的网页无法获取所有元素。您需要执行javascript代码并模拟浏览器滚动以使其加载所有元素,这是解析器无法做到的。有一个API可以启动本地浏览器并模拟滚动(如果您愿意,可以无限次)。我只是不记得名字了……我相信jsoup有一个执行脚本method@BackSlash,我需要更多的信息。注意:我正在使用angular-in-front-endLook进入无头浏览器,支持js:HtmlUnit、phantomjs等。