【问题标题】:Jsoup parse to get text including greater than (>) and less than (<) symbolJsoup 解析获取包含大于 (>) 和小于 (<) 符号的文本
【发布时间】:2017-03-21 17:15:06
【问题描述】:

html中有类似&lt;a&gt;"There is a nothing special &lt;&lt;string&gt;&gt; haha"&lt;/a&gt;的文字。

我想得到包含&lt;&lt;&gt;&gt; 的完整文本,所以输出看起来像There is a nothing special &lt;&lt;string&gt;&gt; haha

我已经完成了

Elements e = element.select("a");
String text = e.text();

但输出是There is a nothing special &lt;&gt; haha

如果打印e.html(),那就是

There is a nothing special &lt;
<string>
&gt;haha
</string>

我该如何解决?

【问题讨论】:

    标签: jsoup


    【解决方案1】:

    输入的 HTML 无效。 jsoup 遵循 HTML5 规范中定义的关于如何解析此类不合格输入的规则。你最终得到的是你看到的e.html()的输出。
    这种转换是有损的,使用 jsoup 时无法检索原始输入。

    附注:字符串There is a nothing special &amp;lt;&amp;lt;string&amp;gt;&amp;gt; haha 在 HTML 文档中应该这样编码:There is a nothing special &amp;lt;&amp;lt;string&amp;gt;&amp;gt; haha

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-06
      • 1970-01-01
      • 1970-01-01
      • 2012-12-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多