導航:首頁 > 凈水問答 > jsoup過濾標簽

jsoup過濾標簽

發布時間:2023-05-16 02:49:10

① 用JSOUP解析HTML,怎樣刪除掉其中的一段DIV標簽及內容

用JSOUP解析HTML刪除掉其中的一段DIV標簽及內容的方法:
1、解析並提取 HTML 元素回
如下:
File input = new File("D:/test.html");
Document doc = Jsoup.parse(input, "UTF-8", "url");
Element content = doc.getElementById("content");
Elements divs= content.getElementsByTag("div");
for (Element div: divs) {
String linkHref = link.attr("id");
String linkText = link.text();
}

2、用答remove方法刪除div

div.remove();

② jsoup 過濾指定標簽問題JAVA

for(Elementlink:links){
//通過link.child(index)或link.getElementsBy<attr>(key,value)獲得部分子節點
mArrayList.add(link.text());
}

③ jsoup如何獲取不在標簽內的文本

先取到body片段,然後過濾掉div標簽和內容,取到的內容就是中國。

④ jsoup得到的結果帶標簽,球打什麼賜教怎麼去掉這些標簽

String str1 = str.text();

⑤ 用JSOUP解析HTML,怎樣刪除掉其中的一段DIV標簽及內容

用JSOUP解析HTML刪除掉其中的一段DIV標簽及內容的方法是根據id刪除。
使用核心方法如下:

doc.getElementById("detail_question").remove()

舉例如下:
從baseHtml這斷代碼中刪除指定id的標簽:
String baseHtml = "<div id='stylized' class='myform'>"
+ "<input id='txt_question' name='preg' type='text' disabled='disabled' style='width:150px;'>"
+ "<div id='detail_question'>Rock</div></div>";

Document doc = Jsoup.parse(baseHtml);
doc.getElementById("detail_question").remove();
Elements elements = doc.select("div");
System.out.println(elements);
輸出的結果中沒有detail_question這個div節點了:
<div id='stylized' class='myform'>
+ "<input id='txt_question' name='preg' type='text' disabled='disabled' style='width:150px;'>

⑥ 利用Jsoup獲取具體標簽屬性值

doc.select("meta[name=description]"),get(0).attr("content")

大致是這么寫的,你可以研究一下JSOUP的選擇器,

chenying99/archive/2013/01/04/2844615,html" target="_blank">http://www.cnblogs.com/chenying99/archive/2013/01/04/2844615.html

⑦ 如何不讓jsoup.parse過濾標簽

//過濾內容中的非法標簽
org.jsoup.nodes.Document document = Jsoup.parse(html);
//只過濾body內容
org.jsoup.nodes.Document body = Jsoup.parse(document.body().html());
//自定義的標簽白名單
Cleaner cleaner = new Cleaner(WhitelistFactory.createWhitelist(WhitelistFactory.EPUB20));
org.jsoup.nodes.Document bodyCleaned = cleaner.clean(body);
document.body().html(bodyCleaned.html());
String newHtml = document.html();

⑧ java 利用jsoup 如何去除一段代碼中的所有html標簽,只留純文本

document.text();

閱讀全文

與jsoup過濾標簽相關的資料

熱點內容
ABS樹脂耐多少溫度 瀏覽:605
迷你飲水機一次性紙杯怎麼做 瀏覽:487
超濾膜膜絲生產過程散發味道 瀏覽:695
反滲透膜水電導率 瀏覽:770
ro膜凈水器比例份額 瀏覽:10
平房家庭飲水機放什麼地方 瀏覽:978
陶氏反滲透膜說明 瀏覽:18
金魚缸過濾活性碳作用 瀏覽:751
揚州市政污水廠污泥處理怎麼樣 瀏覽:607
樹脂光告字製作視頻 瀏覽:996
環氧樹脂g20 瀏覽:478
反滲透電阻率顯示不穩定什麼原因 瀏覽:386
切削液濾芯多少錢一台 瀏覽:397
汽車換機濾芯是什麼意思 瀏覽:34
樹脂玻璃裂紋 瀏覽:352
江浙滬污水過濾器是什麼 瀏覽:420
氣動三聯件過濾器漏氣 瀏覽:246
老款的家用飲水機的水有多少度 瀏覽:248
aaf過濾器官網 瀏覽:668
洗車店的污水處理標准 瀏覽:331