Sky*_*ion 7 html java parsing list jsoup
所以,我试图使用JSoup解析一个简单的列表.不幸的是,程序只返回条目,直到列表中以N开头的条目为止.我不知道为什么会这样.这是我的代码:
public ArrayList<String> initializeMangaNameList(){
Document doc;
try {
doc = Jsoup.connect("http://www.mangahere.com/mangalist/").get();
Elements items = doc.getElementsByClass("manga_info");
ArrayList<String> names = new ArrayList<String>();
for(Element item: items){
names.add(item.text());
}
return names;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
Run Code Online (Sandbox Code Playgroud)
那么为什么List不包含所有条目?网页是否有错误?或者解析器?我可以使用解决方法绕过此问题吗?究竟是什么导致了这个问题呢?
Sky*_*ion 21
好的,发布是由JSoup版本1.72及更高版本的更改引起的.您只需更改默认设置,如下所示:
public ArrayList<String> initializeMangaNameList(){
Document doc;
try {
doc = Jsoup.connect("http://www.mangahere.com/mangalist/").maxBodySize(0).get();
Elements items = doc.getElementsByClass("manga_info");
ArrayList<String> names = new ArrayList<String>();
for(Element item: items){
names.add(item.text());
}
return names;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
Run Code Online (Sandbox Code Playgroud)
}
重要的区别是将maxBodySize设置为0,以便允许无限大小的文件.可以在文档中找到更多信息.这将允许您拥有无限的体型并加载您需要的所有数据.
| 归档时间: |
|
| 查看次数: |
3357 次 |
| 最近记录: |