[英]Nested tag extraction with jsoup
How it is possible to iterate over all tags in a specific tag using jsoup? 如何使用jsoup遍历特定标签中的所有标签? For example, the HTML file looks like
例如,HTML文件看起来像
<br><input ....>
<A HREF=...> <i>some texts</i>
<A HREF=...>
<br><input ....>
<A HREF=...> <i>some texts</i>
<A HREF=...>
<br><input ....>
<A HREF=...> <i>some texts</i>
<A HREF=...>
...
So, for each br
, I want to iterate over the tags input
, a
, i
and a
. 因此,对于每个
br
,我想遍历标签input
a
, i
和a
。 The statement 该声明
Element element = doc.select("br").first();
Will return only br
which is not suitable. 将仅返回不适合的
br
。
UPDATE: 更新:
If I use Elements element = doc.select("br");
如果我使用
Elements element = doc.select("br");
then how can I iterate over element
? 那我该如何遍历
element
呢? If I use 如果我用
Elements element = doc.select("br");
Element e2 = element.get(0).select("i").first();
Then e2 will be null!! 那么e2将为空!
You can't read over input
, a
, i
and a
from br
because there are no children of the br
, because that's select
do : select the children of the element 您无法从
br
读取input
, a
, i
和a
,因为没有br
子代,因为这是select
do:选择元素的子代
The problem is being seen in chat - I'll edit once it's ok 问题正在聊天中显示-一切正常后,我将进行编辑
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.