0
我又來了。jsoup不會刪除元素
我有這段代碼:
this.doc = Jsoup.parse(str);
Elements tables = doc.getElementsByTag("table");
if(tables!=null){
for(Element table : tables){
if(table != null){
Elements tds=table.getElementsByTag("td");
if(tds!=null){
for(Element td : tds){
String[] text=td.text().trim().split("\\s+");
if(text.length<2)td.remove();
}
}
}
}
}
Elements hs = doc.getElementsByTag("h1, h2, h3, h4");
if(hs!=null)for(Element h : hs)if(h != null)h.remove();
Elements blocks = doc.getElementsByTag("div, center, li, p, address, aside, audio, blockquote, canvas, dd, dl, fieldset, figcaption, figure, footer, form, header, hr, hgroup, li, ol, noscript, output, pre, section");
if(blocks!=null){
System.out.println(blocks.size());
for(Element block : blocks){
if(block != null){
String[] text=block.text().trim().split("\\s+");
if(text.length<2)block.remove();
}
}
}
Elements pdp = doc.getElementsByClass("pineDeletePoint");
if(pdp!=null&&pdp.size()>0)pdp.remove();
str = this.doc.outerHtml();
但是我仍然有具有小於這兩個詞在我的HTML中塊元素。
爲什麼我不能刪除它們?
非常感謝您的幫助......
對不起我以前回答過正則表達式有點錯誤。更新它。 – Sage