如何使用jsoup从整个html页面中删除特定标记

Jal*_*rdo 2 html java tags dom jsoup

我正在使用jsoup 1.7.3来编辑一些html文件.

我需要的是从html文件中删除以下标记:

<meta name="GENERATOR" content="XXXXXXXXXXXXXX">
<meta name="CREATED" content="0;0">
<meta name="CHANGED" content="0;0">
Run Code Online (Sandbox Code Playgroud)

当你看到它的标签时,我怎么能这样做,这是我到目前为止所尝试的:

//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();
Run Code Online (Sandbox Code Playgroud)

你有什么建议?

djv*_*uez 7

例如,我建议您使用Jsoup选择器

Document document = Jsoup.parse(html);
Elements selector = document.select("meta[name=GENERATOR]");

for (Element element : selector) {
    element.remove();
}

doc.html(); // returns String html with elements removed
Run Code Online (Sandbox Code Playgroud)