Reputation: 2457
Just curious if this is possible in jsoup
Select an element and it's text but deselect a specified child.
<div>
<p><strong>Location: </strong> Earth</p>
</div>
Is it possible to return just Earth
?
Edit: Also, in the paragraph, Location is static, but Earth is not. i.e you can have
Location: Earth
Location: LA
Location: Mars
Upvotes: 2
Views: 242
Reputation: 43033
You want to use the Element::ownText
method.
String html = "<div>\n" + //
"<p><strong>Location: </strong> Earth</p>\n" + //
"</div>";
Document doc = Jsoup.parse(html);
Element p = doc.select("p").first();
if (p!=null) {
System.out.println(p.ownText());
}
Earth
Upvotes: 4