使用 Jsoup 获取包含内容的跨度
Get the span with content using Jsoup
我有这个html
<span style="font-size:20px">
<span style="font-family:verdana">Text 1</span>
</span>
<span style="font-size:11px">
<span style="fontfamily:arial">Text 2</span>
</span>
我想获取具有内容
的 span 元素
<span style="fontfamily:arial">Text 2</span>
<span style="font-family:verdana">Text 1</span>
我正在使用 JSoup,这是我的尝试
doc.select("span[text!=\"\"]")
doc.select("span[text]")
doc.select("span[content]")
doc.getElementsByTag("span").stream().filter(p -> p.hasText())
有人能帮帮我吗?
提前致谢
实际上,如果您想要 select 跨度,该跨度之间应该有文本,您可以使用以下方法轻松过滤所有跨度:Element.ownText () 不为空。看:
https://jsoup.org/apidocs/org/jsoup/nodes/Element.html#ownText--
public String ownText()
Gets the text owned by this element only; does not get the combined text of all children.
我有这个html
<span style="font-size:20px">
<span style="font-family:verdana">Text 1</span>
</span>
<span style="font-size:11px">
<span style="fontfamily:arial">Text 2</span>
</span>
我想获取具有内容
的 span 元素<span style="fontfamily:arial">Text 2</span>
<span style="font-family:verdana">Text 1</span>
我正在使用 JSoup,这是我的尝试
doc.select("span[text!=\"\"]")
doc.select("span[text]")
doc.select("span[content]")
doc.getElementsByTag("span").stream().filter(p -> p.hasText())
有人能帮帮我吗?
提前致谢
实际上,如果您想要 select 跨度,该跨度之间应该有文本,您可以使用以下方法轻松过滤所有跨度:Element.ownText () 不为空。看:
https://jsoup.org/apidocs/org/jsoup/nodes/Element.html#ownText--
public String ownText()
Gets the text owned by this element only; does not get the combined text of all children.