如何使用 Jsoup 从以下 html 代码中获取“此文本”?
<h2 class="link title"><a href="myhref.html">this text<img width=10
height=10 src="img.jpg" /><span class="blah">
<span>Other texts</span><span class="sometime">00:00</span></span>
</a></h2>
当我尝试时
String s = document.select("h2.title").select("a[href]").first().text();
它返回
本文其他文字00:00
我尝试阅读 apiSelector http://jsoup.org/apidocs/org/jsoup/select/Selector.html在 Jsoup 但无法弄清楚太多。
另外我如何获得类的元素class="link title blah"
(多个班级?)。请原谅我只了解一点 Jsoup 和 CSS。
Use Element#ownText() http://jsoup.org/apidocs/org/jsoup/nodes/Element.html#ownText%28%29代替Element#text() http://jsoup.org/apidocs/org/jsoup/nodes/Element.html#text%28%29.
String s = document.select("h2.link.title a[href]").first().ownText();
请注意,您可以通过将类名选择器连接在一起来选择具有多个类的元素,如下所示h2.link.title
这将选择<h2>
元素至少有both the link
and title
class.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)