Reputation: 1
Hi I could not get the text from html I wanna get this text This is a test text
<div class="rehou">
<span class="tlid-t t">
<span title="" class="">This is a test text</span>
</span>
<span class="tlid-t-v" style="" role="button"></span>
</div>
My java:
Document doc = Jsoup.connect(url).get();
Elements ele= doc.select("span.tlid-t t");
textass = ele.text();
Upvotes: 0
Views: 209
Reputation: 11040
The span
has the two different classes tlid-t
and t
. So if you want to use both classes in your select you should use span.tlid-t.t
instead of span.tlid-t t
.
Elements ele = doc.select("span.tlid-t.t");
String textass = ele.text();
System.out.println(textass);
Which would print This is a test text
.
But this will select the outer span! If the html gets changed the content of textass
will be also changing. If you only want to select the text of the inner span you should use span.tlid-t.t span
.
Elements ele = doc.select("span.tlid-t.t span");
String textass = ele.text();
System.out.println(textass);
This will also print This is a test text
.
Upvotes: 1