簡體   English   中英

如何使用Rhino移除 <scripts> 標簽?

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

我有使用Jsoup解析的HTML電子郵件:-

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

但是它不能刪除腳本標簽:

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

我一直在這樣使用正則表達式:-

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

成功刪除腳本。 但是我遇到了這個問題JSoup來解析<script>標簽

如何使用Rhino解析腳本? 代碼示例將非常有幫助,謝謝。

您不需要使用Rhino刪除<script>標簽。 在JSoup中使用簡單的CSS選擇器並刪除獲得的節點。 這是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