简体   繁体   English

JSoup不会获取所有项目吗?

[英]JSoup will not fetch all items?

So, I am trying to parse a simple list using JSoup. 因此,我正在尝试使用JSoup解析一个简单的列表。 Unfortunately, the program only returns the entries up til the entries that start with N in the list. 不幸的是,该程序仅返回直到列表中以N开头的条目为止的条目。 I do not know why this is the case. 我不知道为什么会这样。 Here is my code: 这是我的代码:

    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;
}

So why does the List not contain all the entries? 那么,为什么列表不包含所有条目? Is there an error with the webpage? 网页有错误吗? Or perhaps the parser? 还是解析器? Can I use a workaround to bypass this issue? 我可以使用替代方法来绕过此问题吗? And what is causing the issue in the first place? 到底是什么引起了该问题?

Okay the issued was caused by a change in JSoup version 1.72 and higher. 好的,发行是由于JSoup 1.72版和更高版本中的更改引起的。 You just need to change the default settings like so: 您只需要像这样更改默认设置:

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;

} }

The important difference is setting the maxBodySize to 0 so that it allows files of unlimited size. 重要的区别是将maxBodySize设置为0,以便允许文件大小不受限制。 More information can be found in the documentation . 可以在文档中找到更多信息。 That will allow you to have unlimited body size and load all the data you need to. 这样一来,您就可以拥有无​​限的机身大小并加载所需的所有数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM