【问题标题】:Parse whole html(avg. size 20MB) through URL using JSOUP使用 JSOUP 通过 URL 解析整个 html(平均大小 20MB)
【发布时间】:2019-08-18 20:57:28
【问题描述】:
Document document = Jsoup.connect("some html url").get();
Elements catelist=  document.select("TEXT");

上面的代码没有给出完整的 html。

【问题讨论】:

  • 这是一个猜测。解析器花费的时间太长,您从中获取的服务器正在超时响应传输。尝试下载到本地文件,然后解析它。

标签: java jsoup html-parsing html-parser


【解决方案1】:

默认情况下,最大正文大小限制为 1MB。您可以使用 maxBodySize(int) 更改该默认值:

//for example to set the max body size to 20 MB
Document document = Jsoup.connect(some html url).timeout(0).maxBodySize(1024*1024*20).get();

//or set it to 0 to have an unlimited size
Document document = Jsoup.connect(some html url).timeout(0).maxBodySize(0).get();

【讨论】:

    【解决方案2】:

    如果你想要整页的html代码 然后使用:

    document.html();
    

    如果你想要特定标签的 html 代码 然后使用:

    catelist.html();
    

    【讨论】:

      猜你喜欢
      • 2013-10-25
      • 2015-12-13
      • 2013-07-13
      • 2012-09-18
      • 2014-12-19
      • 2012-11-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多