[英]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())
有人可以帮助我吗?
提前致谢
实际上,如果要选择跨度应在跨度之间包含文本的跨度,则可以使用以下元素轻松过滤所有跨度:Element.ownText()不为空。 参见: https : public String ownText() Gets the text owned by this element only; does not get the combined text of all children.
public String ownText() Gets the text owned by this element only; does not get the combined text of all children.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.