出于某种原因,Jsoup只提取了2207个元素,尽管肯定有更多元素。例如,类XmlPullParserFactory
的URL虽然位于具有类jd-linkcol
的元素内,但未被读取。
以下是我的代码:
try {
String url = "https://developer.android.com/reference/classes.html";
Document document = Jsoup.connect(url).timeout(0).get();
Elements classes = document.getElementsByClass("jd-linkcol");
BufferedWriter fw = new BufferedWriter(new FileWriter(new File("/tmp/test.txt")));
System.out.println(classes.size());
for (int i = 0; i < classes.size(); i++) {
Elements links = classes.get(i).getElementsByTag("a");
String classUrl = links.attr("abs:href");
if (classUrl.contains("XmlPullParserFactory")) {
System.out.println(classUrl);
}
fw.write(classUrl + "\n");
}
fw.flush();
fw.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
我正在使用Jsoup 1.7.3,我暂时没有更新。
答案 0 :(得分:1)
默认情况下,最大体型限制为1MB。使用默认设置,您只能获得从AbsListView到MediaRouter.UserRouteInfo的前2207个元素,这些元素符合默认大小1MB。要获取所有元素,您只需使用以下命令更改默认设置:
Document document = Jsoup.connect(url).timeout(0).maxBodySize(1024*1024*10).get();
//for example to set the max body size to 10 MB
或
//to set it to unlimited size
Document document = Jsoup.connect(url).timeout(0).maxBodySize(0).get();