簡體   English   中英

使用jSoup,如何提取沒有任何類型的標簽包圍的文本?

[英]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()的結果。

在這里回答(感謝):

Jsoup-提取文本

懶惰的釋義版本:

// 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM