如何使用Jsoup在ArrayList中的元素内存储文本?
问题描述:
我想存储在ArrayList中的div内的p元素内部的文本。下面的HTML给出:如何使用Jsoup在ArrayList中的元素内存储文本?
<div class="copy">
<p>First text</p>
<p>Second text</p>
<p>Third text</p>
</div>
我试着下面的代码,但它加到上述所有并将其存储为一体的,而不是单独存储它们的:
Elements tips= doc.select("div.copy");
for(Element tip: tips) {
tipsArray.add(tip.text());
}
什么我错在这里做什么?谢谢。
答
只需使用:
Elements tips= doc.select("div.copy > p");
for(Element tip: tips) {
tipsArray.add(tip.html());
}
谢谢。有效。 – 2014-09-02 07:04:58
@BidhanA很高兴听到它! – geoand 2014-09-02 07:06:29