【发布时间】:2015-08-16 18:06:59
【问题描述】:
我想在使用 JSoup 时保留 html 实体。这是来自网站的 utf-8 测试字符串:
String html = "<html><body>hello — world</body></html>";
String parsed = Jsoup.parse(html).toString();
如果以 utf-8 格式打印解析后的输出,看起来序列 被转换为代码点值为 151 的字符。
有没有办法让 JSoup 在输出为 utf-8 时保留原始实体?如果我以 ascii 编码输出:
Document.OutputSettings settings = new Document.OutputSettings();
settings.charset(Charset.forName("ascii"));
Jsoup.parse(html).outputSettings(settings).toString();
我会得到:
hello — world
这就是我要找的。p>
【问题讨论】:
-
我认为没有办法做到这一点。但是应该可以输出为 ASCII,(你已经在做的事情)并使用它,因为 ASCII Charset 与 utf-8 兼容。
标签: jsoup