如何防止jsoup转换特殊字符? [英] How to prevent jsoup converting special characters?
本文介绍了如何防止jsoup转换特殊字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请查看以下简化示例:
public static void main(String[] args) {
String html = "<html>\n" +
" <head></head>\n" +
" <body>\n" +
" <div> \n" +
" <p> 2 <= X </p> \n" +
" </div>\n" +
" </body>\n" +
"</html>";
Document doc = Jsoup.parse(html);
System.out.println(doc.select("p").outerHtml());
}
打印出< p> 2& lt; = X< / p>
但我希望所选的html部分打印出来:< p> 2< = X< / p>
。我怎么能告诉jsoup不要转换'<'符号?
This prints out <p> 2 <= X </p>
but i am expecting the selected html part to be printed out as it was : <p> 2 <= X </p>
. How can i tell jsoup not to convert the '<' symbol?
推荐答案
可以使用jsoup。
使用jSoup 1.8.3,可以使用方法 Parser.unescapeEntities 保留原始html。
With jSoup 1.8.3 it is possible to use the method Parser.unescapeEntities that retain the original html.
import org.jsoup.parser.Parser;
...
String html = Parser.unescapeEntities(original_html, false));
在以前的某些版本中,此方法不存在。
In some previous releases this method is not present.
这篇关于如何防止jsoup转换特殊字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文