簡體   English   中英

Jsoup刪除以Href開頭的link href屬性

[英]Jsoup Remove the link href attribute starts with Href

我想刪除從http://goo.glhttps://goo.gl的鏈接href屬性。

以下是我的代碼,但並非完全沒有錯誤消息。

我不知道該怎么辦。 請幫我。

public class NewClass {

    public static void main(String[] args) {
        try {
            Document connect = Jsoup.connect("http://blogtamsu.vn/ngoc-trinh-duoc-goi-la-hinh-mau-bao-hieu-tot-doi-dep-dao.html").get();
            Elements selects = connect.select("div.remain_detail");
            String levels = "a[href^=http://goo.gl],a[href^=https://goo.gl]";
            for (String level : levels.split(",")) {
                selects.remove(level);
            }
            System.out.println(Jsoup.clean(selects.html(), Whitelist.relaxed()));
        } catch (IOException ex) {
            Logger.getLogger(NewClass.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

使用regex選擇和從selects刪除:

selects.select("a[href~=(http|https)://goo.gl]").remove()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM