How to get this text using Jsoup?
How do I get “this text” from the following HTML using Jsoup?
<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>
When i try
String s = document.select("h2.title").select("a[href]").first().text();
he returns
this textOther texts00: 00
I tried to read the api for Selector in Jsoup but couldn't understand much.
Also, how do I get a class element class="link title blah"(multiple classes?). Forgive me, I only know a bit of Jsoup and CSS.
+5
1 answer
Use Element#ownText()instead Element#text().
String s = document.select("h2.link.title a[href]").first().ownText();
, , , , h2.link.title, <h2>, link, title.
+9