[英]How to store text inside elements in an ArrayList using Jsoup?
I am trying to store the text inside of the p elements which are inside a div in an ArrayList. 我试图将文本存储在ArrayList中的div内的p元素内。 The HTML is given below:
HTML如下所示:
<div class="copy">
<p>First text</p>
<p>Second text</p>
<p>Third text</p>
</div>
I tried the following code but it concatenates all of the above and stores them as one instead of storing them separately: 我尝试了以下代码,但将以上所有内容串联在一起,并将它们存储为一个,而不是单独存储:
Elements tips= doc.select("div.copy");
for(Element tip: tips) {
tipsArray.add(tip.text());
}
What am I doing wrong here? 我在这里做错了什么? Thanks.
谢谢。
Just use: 只需使用:
Elements tips= doc.select("div.copy > p");
for(Element tip: tips) {
tipsArray.add(tip.html());
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.