Revolution Revolution - 6 months ago 73
Android Question

How to get Text from Parent div only using Jsoup in Android

I am working with

Android Application
using
Jsoup
for
extracting
text from
website
, in the below
Html
I want to get text of the
parent div
only. What I want is to display
Date & Time
which is in the
parent div
of
class "fr"
.

<div class="fr">
<div id="newssource">
<a href="http://nhl.com" class="newssourcelink" target="_blank">
Philadelphia Flyers
</a>
</div>
April 15, 2014, 11:13 a.m.
</div>


What I have tried.

for(Element detailsDate:document.getElementsByClass("fr")){
newsDate.add(detailsDate.clone().children().remove().last().text().trim());
}


It only get text from
child div
i.e.
"Philadelphia Flyers"
which is in the
"a" tag
, but I want to display the
Date & Time
only.

Answer

I have found the answer by myself. Just Posted here for some one else with same issue.

for(Element detailsDate:document.getElementsByClass("fr")){
    newsDate.add(detailsDate.getElementById("newssource").nextElementSibling());
}
Comments