[英]Obtaining JSoup Elements in certain order
In one <div>
element I have three types of elements (among the others): 在一个
<div>
元素中,我具有三种类型的元素(在其他元素中):
<span class="some_name_1">
<div class="some_name_2">
<p>
The problem is that I don't know how their number and the order they're in. So what I would need is to have all of these elements shown above in some kind of array so I could iterate over them. 问题是我不知道它们的数量和排列顺序。因此,我需要将所有这些元素以某种数组的形式显示,以便对它们进行迭代。
I am quite new to JSoup - how could I achieve such thing? 我对JSoup还是很陌生-我怎么能做到这一点? The order is crucial for me.
订单对我来说至关重要。
Thanks! 谢谢!
Hmm, you need to iterate on elements? 嗯,您需要遍历元素吗? This is simple.
这很简单。
Document doc = Jsoup.connect(url).get();
Element div = doc.select("div").first(); //here you get your parent div
for (Element element : div.children()) {
//Here you can acccess all childs of your div
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.