简体   繁体   English

如何使用Rhino移除 <scripts> 标签?

[英]How do I use Rhino to remove <scripts> tag?

I have an HTML email message that I parse using Jsoup :- 我有使用Jsoup解析的HTML电子邮件:-

Jsoup.parse(bizmsg.getMessageBody()).text()

But it can't remove script tags :- 但是它不能删除脚本标签:

<script>
document.write("Bazinga!")
</script>

I have been using regex like this :- 我一直在这样使用正则表达式:-

String(v).replace(/(?:<script.*?>)((\n|\r|.)*?)(?:<\/script>)/ig, "");

to successfully remove scripts. 成功删除脚本。 But I came across this question JSoup to parse <script> tag 但是我遇到了这个问题JSoup来解析<script>标签

How do I use Rhino to parse scripts ? 如何使用Rhino解析脚本? Code-Sample would be very helpful, thanks. 代码示例将非常有帮助,谢谢。

You don't need to use Rhino to remove <script> tags. 您不需要使用Rhino删除<script>标签。 Use simple CSS selectors in JSoup and remove the obtained nodes. 在JSoup中使用简单的CSS选择器并删除获得的节点。 Here a minimal example on www.google.com 这是www.google.com上的一个最小示例

public static void main(String[] args) throws MalformedURLException, IOException {
    Document doc = Jsoup.parse(new URL("http://www.google.com"),5000);
    Elements elems = doc.select("script");
    for (Element elem : elems)
        elem.remove();
    System.out.println(doc);

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM