2015-11-26 187 views
2

開始我想刪除的鏈接href屬性與http://goo.glhttps://goo.gl開始。Jsoup刪除鏈接href屬性與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); 
     } 
    } 
} 

回答

2

使用regex選擇和selects刪除:

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

我感覺好極了我的命令是由您的answer.Thank成功執行你了 –