简体   繁体   中英

JSoup - Parsing this nested HTML unordered list

I'm trying to parse this nested HTML from a website but I just can't seen to figure out how to get the data out of the unordered list.

<ul class="no-bullet participants-list" data-registrations="registrants">
     <li class="participant" data-participant-id="512028" data-registrations="registrant">
         <div class="row collapse participant-info">
             <div class="large-1 small-2 columns"> 
                 <figure class="participant-avatar">
                    <a class="user-profile-link" href="THE LINK I WANT">

What I've tried

for(Element row : doc.select("ul.no-bullet participants-list")) {
         row.select("li.participant")
             .select("div.row collapse participant-info")
             .select("div.large-1 small-2 columns")
             .select("figure.participant-avatar")
             .select("a.href").text());
}

Not sure what I'm doing wrong

As I understand you are looking for href attribute inside a tag Your's select statement is not correct because you use space instead of dot in order to choose class

Instead of this

doc.select("ul.no-bullet participants-list")

Use this

doc.select("ul.no-bullet.participants-list a").first().attr("href")

As you see I chose first a tag and fetched href from this tag

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