我有以下html:
text text text text text
如何使用Jsoup库在每个标签中将“文本”替换为“单词”.
我想看看:
word word word word word
感谢您的任何建议!
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
}
}
}