jsoup去掉link以href开头的href属性
Jsoup Remove the link href attribute starts with Href
我想删除以 http://goo.gl to https://goo.gl 开头的 link 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
到 select 并从 selects
中删除:
selects.select("a[href~=(http|https)://goo.gl]").remove()
我想删除以 http://goo.gl to https://goo.gl 开头的 link 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
到 select 并从 selects
中删除:
selects.select("a[href~=(http|https)://goo.gl]").remove()