[英]Using jSoup, how can I extract text that isn't surrounded by any type of tags?
我在這里有此HTML代碼:
<hr />
<h3>Academic Recovery and Probation Conference Journal</h3>The Recovery Progress Journal is used to
record and guide conference discussions and to monitor students’ academic, behavioral and social
progress.
<br />
如您所見,“ h3”標題下的文本周圍沒有任何標簽? 我正在使用jSoup將此信息放入Android應用程序。 如果沒有標記來定義該段文本,我將如何提取?
我認為在沒有任何其他解析的情況下單獨使用Jsoup是不可能的。 Jsoup在DOM中定位元素,然后允許您訪問元素的數據。
您將必須找到包圍所需段落的最小元素,在其上運行.text(),然后自己解析.text()的結果。
在這里回答(感謝):
懶惰的釋義版本:
// You need to get Nodes, not Elements
Document doc = Jsoup.parse(str);
Element div = doc.select("div").first();
for (Node node : div.childNodes()) {
System.out.println(
String.format(
"%s %s",
node.getClass().getSimpleName(),
node.toString()
)
);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.