本文介绍了如何获取文本从父div只使用Jsoup在Android中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用 Android Application
使用 Jsoup
为提取
c> 的文本
。我想要的是显示网站
,在下面 Html
div Date&时间
,其位于 classfr
的父div
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>
我尝试了。
for(Element detailsDate:document.getElementsByClass("fr")){
newsDate.add(detailsDate.clone().children().remove().last().text().trim());
}
它只能从 child div
ie Philadelphia Flyers
这是在a标签
,但我想显示日期&时间
。
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.
推荐答案
我自己找到答案。
for(Element detailsDate:document.getElementsByClass("fr")){
newsDate.add(detailsDate.getElementById("newssource").nextElementSibling());
}
这篇关于如何获取文本从父div只使用Jsoup在Android中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!