Using jsoup, I know how to extract the text of an entire div:
<div class="c">
<a href="/relurl.php?refid=7">First Anchor Text</a>
Something in Between
<a href="/john.doe?refid=7">Second Anchor Text</a>
</div>
Such that div.text() yields:
First Anchor Text Something in Between
Second Anchor Text
And I know how to extract the text of each anchor separately, such that the first a.text() yields:
First Anchor Text
But is there an elegant way in Jsoup to extract only Something in Between?
(I can of course extract the 2 a.text() and “subtract” them from div.text() but I don’t consider this elegant)
Use
Element#ownText(). Here’s an extract from the linked javadoc:So, this should do: