Ma Tâm
Ma Tâm

Reputation: 307

Jsoup Remove the link href attribute starts with Href

I want to remove the link href attribute starts with http://goo.gl to https://goo.gl .

Below is my code, but it is not exactly no error message.

I do not know what should I do. Please help me.

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);
        }
    }
}

Upvotes: 2

Views: 1709

Answers (1)

chengpohi
chengpohi

Reputation: 14217

use regex to select and remove from selects:

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

Upvotes: 3

Related Questions