如何在android中使用jsoup获取标签内的内容?
我经过长时间的努力搜寻,却发现没有任何帮助。我真的不知道该怎么办。我在下面写了所有细节。我尝试过但没有成功。
我的HTML代码:
<div id="content-post">
<article class="post clearfix">
<figure class="post-image"></figure>
<header></header>
Line 1
Line 2
<br></br>
<br></br>
Line 4
Line 5
Line 6
Line 7
<br></br>
<br></br>
Line 8
Line 9
<br></br>
<br></br>
Line 10
Line 11
<p></p>
<div class="news_detail">
<div class="news_soc"></div>
</div>
</article>
</div>
我需要将第1行放到第11行。 我想把它们放到一个数组中。
更新:
<div id="content-post">
<article class="post clearfix">
<figure class="post-image">
<img src="../../../../../upload/news/2014/07/large/JuiR1404499837lucxqg.jpg" />
<h1>Agree</h1>
</figure>
<header>
<p class="post-meta">2014</p>
</header> Line 1
Line 2
<br></br>
<br></br>
Line 4
Line 5
Line 6
Line 7
<br></br>
<br></br>
Line 8
Line 9
<br></br>
<br></br>
Line 10
Line 11
<p></p>
<div class="news_detail">
<div class="news_soc">
<a href="https://plus.google.com/share?" target="_blank"><img alt="Google+" src="../../../../theme/image/soc_gp.jpg"></a>
<a href="https://twitter.com/intent/tweet/" target="_blank"><img alt="Twitter" src="../../../../theme/image/soc_tw.jpg"></a>
<a href="https://www.facebook.com/sharer/" target="_blank"><img alt="Facebook" src="../../../../theme/image/soc_fb.jpg"></a>
</div>
<div class="news_auth">
Send By Jack
</div>
</div>
</article>
</div>
我的代码:
int timeOut = 30 * 1000;// 30 second.
String url =CommonMethods.getCurrentSite() + URLEncoder.encode(news.getLink(), "UTF-8").replace("%2F","/");
_doc = Jsoup.connect(url)
.timeout(timeOut)
.get();
if (isCancelled()) { // If Cancel Read Content News return Null
return null;
}
_ContentRegion = _doc.getElementById("content-post");
//I really do not know what to do.
答案 0 :(得分:1)
我发现:
_ContentRegion = _doc.getElementById("content-post").select("article > p");
for (Element ee : _ContentRegion){
Log.d("ownText",ee.ownText());
}