如何使用jsoup从整个html页面中删除特定标签
问题描述:
我使用jsoup 1.7.3来编辑一些html文件。如何使用jsoup从整个html页面中删除特定标签
我需要的是从HTML文件中删除以下标签:
<meta name="GENERATOR" content="XXXXXXXXXXXXXX">
<meta name="CREATED" content="0;0">
<meta name="CHANGED" content="0;0">
正如你看到它的标签,我怎么能做到这一点,这里是我试过到目前为止:
//im pretty sure that the <meta> tag is nested in the <header>
but removing the whole header is bad practice.
Document docsoup = Jsoup.parse(htmlin);
docsoup.head().remove();
你有什么建议?
答
我推荐你使用Jsoup selectors,例如
Elements selector = docsoup.select("meta[name=GENERATOR]");
for (Element element : selector) {
element.remove();
}