And*_*luZ 1 html java parsing jericho-html-parser
使用杰里科,我需要解析这样的事情:
<html>
<div class="title">
Spoon bows
<br/>
<span>
A Matrix scene.
<br/>
Matrix 1
</span>
</div>
</html>
Run Code Online (Sandbox Code Playgroud)
我想解析"Spoon bows",但我<div>使用以下代码获取标记内的全部内容:
List<Element> list = item.getAllElementsByClass("title");
if(list!=null) {
Element title = list.get(0);
if(title!=null) {
String text = title.getContent().getTextExtractor().toString();
}
}
}
Run Code Online (Sandbox Code Playgroud)
这应该可以帮到你:
private String getTextContent(Element elem) {
String text = elem.getContent().toString();
final List<Element> children = elem.getChildElements();
for (Element child : children) {
text = text.replace(child.toString(), "");
}
return text;
}
Run Code Online (Sandbox Code Playgroud)