如何防止JSoup清理程序篡改内容 [英] How to prevent JSoup cleaner tampering the content
本文介绍了如何防止JSoup清理程序篡改内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要JSoup从一些HTML字符串中删除脚本,并为此使用以下代码段:
I need JSoup to remove scripts from some HTML string, and using this snippet for that:
Document unsafeDoc = Jsoup.parse(unsafeHtml);
Document safeDoc = cleaner.clean(unsafeDoc);
OutputSettings o = safeDoc.outputSettings();
o.escapeMode(EscapeMode.xhtml);
return safeDoc.select("body").html();
但是它正在<br>
标记之前插入多余的空间,将和'转换为"
;和'
等.除了JSoup之外,其他任何库的帮助或建议.
But it is inserting extra space before <br>
tags, converting " and ' to "
; and '
etc., which I don't want. Could not find a way to achieve this. Would appreciate any help or recommendations of any other library than JSoup doing this.
谢谢, 桑杰
推荐答案
尝试使用:
safeDoc.outputSettings().prettyPrint(false);
我遇到了同样的问题,并解决了该问题.
I had the same problem and that fixed it.
这篇关于如何防止JSoup清理程序篡改内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文