1

我用的是jsoup-1.6.0,解析html标签字符串,只包含字符串内容“0”,但是jsoup返回null,我明白...

例如:

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"

这是为什么?


回答:

应该是bug,binary_runner说jsoup-1.3.3运行良好,我测试jsoup-1.5.2也运行良好。所以,我决定使用 jsoup-1.5.2 。

感谢 binary_runner!

4

3 回答 3

1

This is a bug in jsoup 1.6.0 caused by an incorrect null check in the new HTML parser implementation.

I have fixed the issue and it will be available in 1.6.1, which I'll in the next couple of days.

于 2011-06-25T09:03:04.947 回答
0

我不确定。可能,我猜,这是一个 Jsoup 的错误。我可以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"
于 2011-06-24T07:27:27.897 回答
0

显然是一个错误,适用于 JSoup 1.3.3 。

于 2011-06-24T07:57:21.213 回答