简体   繁体   English

当Jsoup解析仅包含“ 0”的HTML标记时,将返回null吗?

[英]When Jsoup parse Html tag that only included “0”, null will be returned?

I use jsoup-1.6.0,parse html tag string, that only include string content "0", but jsoup return null, I understand... 我使用jsoup-1.6.0,解析html标记字符串,只包含字符串内容“ 0”,但是jsoup返回null,我理解...

examply: 例如:

String html = "<span>0</span>";
Document doc = Jsoup.parse(html);
Elements eles = doc.getElementsByTag("span");
Element span = eles.get(0);
System.out.println(span.hasText());//false
System.out.println(span.ownText());//null, but I hope the result is "0"

It's why? 这是为什么呢?


Answer: 回答:

It should be a bug, binary_runner says jsoup-1.3.3 works well, I test jsoup-1.5.2 works well too. 应该是一个错误,binary_runner说jsoup-1.3.3很好,我测试了jsoup-1.5.2也很好。 so, I decide use jsoup-1.5.2 . 因此,我决定使用jsoup-1.5.2。

Thanks binary_runner! 谢谢binary_runner!

This is a bug in jsoup 1.6.0 caused by an incorrect null check in the new HTML parser implementation. 这是一个错误的jsoup 1.6.0所引起的新的HTML解析器实现了不正确的空检查。

I have fixed the issue and it will be available in 1.6.1 , which I'll in the next couple of days. 我已经解决了这个问题 ,它将在1.6.1 ,我将在接下来的几天中使用。

I'm not sure. 我不确定。 probably, i guess, it's a Jsoup's bug. 我猜可能是Jsoup的错误。 I could a with following code. 我可以a与下面的代码。

String html = "<span>a</span>";
Document doc = Jsoup.parse(html);
Elements eles = doc.getElementsByTag("span");
Element span = eles.get(0);
System.out.println(span.hasText());//true
System.out.println(span.ownText());//"a"

显然,一个错误可以与JSoup 1.3.3一起很好地工作。

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

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