JSoup不会获取所有项目? [英] JSoup will not fetch all items?

查看:100
本文介绍了JSoup不会获取所有项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我试图用JSoup解析一个简单的列表。不幸的是,该程序只会返回条目直到列表中以N开头的条目。我不知道为什么会这样。这是我的代码:

  public ArrayList< String> initializeMangaNameList(){
Document doc;
尝试{
doc = Jsoup.connect(http://www.mangahere.com/mangalist/).get();
Elements items = doc.getElementsByClass(manga_info);
ArrayList< String> names = new ArrayList< String>(); (Element item:items)

names.add(item.text());
}
返回名称;
} catch(IOException e){
// TODO自动生成的catch块
e.printStackTrace();
}
返回null;
}

那么为什么列表不包含所有条目呢?网页有错误吗?或者也许解析器?我可以使用解决方法绕过此问题吗?首先是什么导致了这个问题?

解决方案

好的,这个问题是由JSoup版本1.72及更高版本。您只需要更改默认设置,如下所示:

  public ArrayList< String> initializeMangaNameList(){
Document doc;
尝试{
doc = Jsoup.connect(http://www.mangahere.com/mangalist/).maxBodySize(0).get();
Elements items = doc.getElementsByClass(manga_info);
ArrayList< String> names = new ArrayList< String>(); (Element item:items)

names.add(item.text());
}
返回名称;
} catch(IOException e){
// TODO自动生成的catch块
e.printStackTrace();
}
返回null;

}



重要的区别在于设置将maxBodySize设置为0,以便它允许无限大小的文件。更多信息可以在文档中找到。
这将允许您拥有无限的身体尺寸并加载所有需要的数据。


So, I am trying to parse a simple list using JSoup. Unfortunately, the program only returns the entries up til the entries that start with N in the list. 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. 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. 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.

这篇关于JSoup不会获取所有项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆