简体   繁体   中英

Nested tag extraction with jsoup

How it is possible to iterate over all tags in a specific tag using jsoup? For example, the HTML file looks like

<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 . The statement

Element element = doc.select("br").first();

Will return only br which is not suitable.

UPDATE:

If I use Elements element = doc.select("br"); then how can I iterate over element ? If I use

Elements element = doc.select("br");
Element e2 = element.get(0).select("i").first();

Then e2 will be null!!

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


The problem is being seen in chat - I'll edit once it's ok

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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