以下是传递给 JSOUP 的 HTML 字符串
<p id="pid">¨This is string using for testing</p>
Document doc = Jsoup.parse(htmlString);
String text = doc.getElementById("pid").text();
提取属性文本后,结果如下
¨This is string using for testing
但问题在于“此
隐藏的十六进制字符已添加到其中。如果我在 notepad++ hexEditor 中查看字符串 ¡This
为 c2a854686973
(¡This
)
最佳答案
But issue is for
¨This
hidden hex character is added to it.
您可以更改加载 HTML 代码的方式。只要您提供字符集名称,Jsoup 就会接受解析 InputStream
。
示例
String s = "<p id=\"pid\">¨This is string using for testing</p>";
Document doc = Jsoup.parse(new ByteArrayInputStream(s.getBytes()), "ASCII", "");
System.out.println(doc);
输出
<html>
<head></head>
<body>
<p id="pid">¨This is string using for testing</p>
</body>
</html>
关于java - JSOUP:HTML 符号 ¡ 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36770552/