新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
java如何去掉html標(biāo)簽頁
要去掉HTML標(biāo)簽,可以使用正則表達(dá)式或者Java的Jsoup庫,這里給出一個使用Jsoup庫的方法:

1、需要添加Jsoup庫到項目中,如果你使用的是Maven項目,可以在pom.xml文件中添加以下依賴:
org.jsoup jsoup 1.14.3
2、使用Jsoup的clean方法去除HTML標(biāo)簽:
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
public class RemoveHtmlTags {
public static void main(String[] args) {
String html = "標(biāo)題 這是一個段落。
這是另一個段落。
";
String text = removeHtmlTags(html);
System.out.println(text);
}
public static String removeHtmlTags(String html) {
Document document = Jsoup.parse(html);
return document.text();
}
}
這段代碼會輸出:
標(biāo)題 這是一個段落。 這是另一個段落。
這樣就去除了HTML標(biāo)簽,只保留了文本內(nèi)容。
網(wǎng)站標(biāo)題:java如何去掉html標(biāo)簽頁
URL地址:http://www.dlmjj.cn/article/djddijp.html


咨詢
建站咨詢
