I'm not familiar with Mojo::DOM but this is how I would do it using HTML::TreeBuilder::XPath. If you don't know them already you will need to learn some Xpath expressions, but that is a useful thing to know.

Note that <i class="fa fa fa-phone"></i> does not actually contain the phone number - it is a FontAwesome element that displays an icon - so you need to go up one level to get the content: $phone_icon->parent->as_text. Same goes for all the other FontAwesome elements.

You may need to add checks for elements that are missing in some members. PS: I had to fix the image source in your example.

use Data::Dumper; use HTML::TreeBuilder::XPath; my $data = join '', <DATA>; my $tree = HTML::TreeBuilder::XPath->new; $tree->parse($data); $tree->eof; my %members; my @items = $tree->findnodes('//ul[@id="members-list"]/li'); for my $item (@items) { my ($member_link) = $item->findnodes('div/div[@class="item-title"] +/a'); my $member = $member_link->as_text; my ($avatar_img) = $item->findnodes('div[@class="item-avatar"]/a/i +mg'); my $avatar = $avatar_img->attr('src'); my ($phone_icon) = $item->findnodes('div//i[@class="fa fa fa-phone +"]'); my $phone = $phone_icon->parent->as_text; my ($mobile_icon) = $item->findnodes('div//i[@class="fa fa fa-mobi +le-phone"]'); my $mobile = $mobile_icon->parent->as_text; $members{$member} = { 'avatar_url' => $avatar, 'fa fa fa-phone' => $phone, 'fa fa fa-mobile-phone' => $mobile, }; } print Dumper(\%members); __DATA__ <ul id="members-list" class="item-list" role="main"> <li> <div class="item-avatar"> <a href="https://intra.example.com/coworkers/dantealighier +i/"><img src="SRCURL"></a> <span class="member-role">Sottoscrittore</span> + </div> <!-- .item-avatar --> <div class="item"> <div class="item-title"> <a href="https://intra.example.com/coworkers/dantealig +hieri/" class="heading"><h3>Dante Alighieri</h3></a> + </div> <div class="item-meta"><span class="activity">active 6 + days ago, 19 hours ago</span></div> <div class="woffice-xprofile-list"> <span><i class="fa fa fa-phone"></i>011111111</spa +n> <span><i class="fa fa fa-mobile-phone"></i>3333333 +33</span> <span><i class="fa fa fa-envelope-o"></i>dante.ali +ghieri@example.com</span> <span><i class="fa fa fa-check"></i>Poets and Writ +ers</span> </div> </div> <div class="action"></div> <div class="clear"></div> </li> <li> <div class="item-avatar"> <a href="https://intra.example.com/coworkers/francescopetr +arca/"><img src="SRCURL"></a> <span class="member-role">Sottoscrittore</span> + </div> <!-- .item-avatar --> <div class="item"> <div class="item-title"> <a href="https://intra.example.com/coworkers/francesco +ptetrarca/" class="heading"><h3>Francesco Petrarca</h3></a> + </div> <div class="item-meta"><span class="activity">active 7 + days ago, 22 hours ago</span></div> <div class="woffice-xprofile-list"> <span><i class="fa fa fa-phone"></i>02222222</span +> <span><i class="fa fa fa-mobile-phone"></i></span> <span><i class="fa fa fa-envelope-o"></i>francesco +.petrarca@example.com</span> <span><i class="fa fa fa-check"></i>Poets and Writ +ers</span> </div> </div> <div class="action"></div> <div class="clear"></div> </li> </ul>

Output:

$VAR1 = { 'Dante Alighieri' => { 'avatar_url' => 'SRCURL', 'fa fa fa-phone' => '011111111' 'fa fa fa-mobile-phone' => '333333333' }, 'Francesco Petrarca' => { 'avatar_url' => 'SRCURL' 'fa fa fa-phone' => '02222222', 'fa fa fa-mobile-phone' => '' } };

In reply to Re: extracting sub elements from DOM by class by tangent
in thread extracting sub elements from DOM by class by Discipulus

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.