简体   繁体   English

使用jsoup提取嵌套标签

[英]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 aia 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读取inputaia ,因为没有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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM