的每一个标签,我有以下的HTML:使用Jsoup库中的每一个标签我怎么能代替“文本”中使用Jsoup
<html>
<head>
</head>
<body>
<div id="content" >
<p>text <strong>text</strong> text <em>text</em> text </p>
</div>
</body>
</html>
我怎么能代替“文”到“字”。 我想看:
<html>
<head>
</head>
<body>
<div id="content" >
<p>word <strong>word</strong> word <em>word</em> word </p>
</div>
</body>
</html>
谢谢你的任何建议!
UPD: 谢谢你的回答,但我发现通用的方法:
Element entry = doc.select("div").first();
Elements tags = entry.getAllElements();
for (Element tag : tags) {
for (Node child : tag.childNodes()) {
if (child instanceof TextNode && !((TextNode) child).isBlank()) {
System.out.println(child); //text
((TextNode) child).text("word"); //replace to word
}
}
}