Skip to content

Instantly share code, notes, and snippets.

@hesco
Last active August 29, 2015 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hesco/c2fca7f23eaca266993d to your computer and use it in GitHub Desktop.
Save hesco/c2fca7f23eaca266993d to your computer and use it in GitHub Desktop.
'phones' => bless( [
bless( do{\(my $o = bless( {
'xml' => undef,
'tree' => [
'tag',
'div',
{
'itemprop' => 'telephone',
'class' => 'mn-member-phone1'
},
undef,
[
'text',
'(912) 634-7377',
${$VAR1->{'phones'}[0]}->{'tree'}
]
]
}, 'Mojo::DOM::HTML' ))}, 'Mojo::DOM' ),
bless( do{\(my $o = bless( {
'xml' => undef,
'tree' => [
'tag',
'div',
{
'itemprop' => 'telephone',
'class' => 'mn-member-phone2'
},
undef,
[
'text',
'(800) 569-1955',
${$VAR1->{'phones'}[1]}->{'tree'}
]
]
}, 'Mojo::DOM::HTML' ))}, 'Mojo::DOM' )
], 'Mojo::Collection' )
This:
sub parse_phones {
my $self = shift;
my $dom = shift;
my $phones = $dom->at( '#mn-member-general > div > div.mn-member-basicinfo' )->attr( 'itemprop' => 'telephone' );
return $phones;
}
hoping to see:
'phones' => [ '912-555-1212', '800-555-1212' ],
got me this close:
'phones' => bless( do{\(my $o = bless( {
'tree' => [
'tag',
'div',
{
'itemscope' => 'itemscope',
'class' => 'mn-member-basicinfo',
'itemtype' => 'http://schema.org/PostalAddress',
'itemprop' => 'telephone'
},
undef,
[
'text',
'
',
${$VAR1->{'phones'}}->{'tree'}
],
[
'tag',
'div',
{
'itemprop' => 'streetAddress',
'class' => 'mn-member-address'
},
${$VAR1->{'phones'}}->{'tree'},
[
'text',
'103 Main Street',
${$VAR1->{'phones'}}->{'tree'}->[5]
]
],
[
'text',
'
',
${$VAR1->{'phones'}}->{'tree'}
],
[
'tag',
'div',
{
'class' => 'mn-member-cistpost'
},
${$VAR1->{'phones'}}->{'tree'},
[
'tag',
'span',
{
'itemprop' => 'addressLocality'
},
${$VAR1->{'phones'}}->{'tree'}->[7],
[
'text',
'St. Simons Island',
${$VAR1->{'phones'}}->{'tree'}->[7]->[4]
]
],
along with other cruft . . .
[
'tag',
'div',
{
'itemprop' => 'telephone',
'class' => 'mn-member-phone1'
},
${$VAR1->{'phones'}}->{'tree'},
[
'text',
'(912) 555-1212',
${$VAR1->{'phones'}}->{'tree'}->[9]
]
],
[
'tag',
'div',
{
'class' => 'mn-member-phone2',
'itemprop' => 'telephone'
},
${$VAR1->{'phones'}}->{'tree'},
[
'text',
'(800) 555-1212',
${$VAR1->{'phones'}}->{'tree'}->[11]
]
],
[
'text',
'
',
${$VAR1->{'phones'}}->{'tree'}
],
[
'tag',
'div',
{
'itemprop' => 'faxNumber',
'class' => 'mn-member-fax'
},
${$VAR1->{'phones'}}->{'tree'},
[
'text',
'(912) 555-1234 (fax)',
${$VAR1->{'phones'}}->{'tree'}->[13]
]
],
[
'text',
'
',
${$VAR1->{'phones'}}->{'tree'}
]
],
'xml' => undef
}, 'Mojo::DOM::HTML' ))}, 'Mojo::DOM' ),
<div id="mn-member-general" class="mn-section">
<div class="mn-section-content">
<div id="mn-member-name-nologo">Cal Duke Publishing, Inc.</div>
<div class="mn-memberinfo-block-actions">
<ul>
<li id="mn-memberinfo-block-website"><a itemprop="url" href="http://www.caldukepublishing.com/" class="mn-print-url" onclick="MNI.Hit.MemberWebsite(2076)" title="Visit the website of Cal Duke Publishing, Inc." target="_blank">Visit Website</a></li>
</ul>
</div>
<div itemprop="address" itemscope="itemscope" itemtype="http://schema.org/PostalAddress" class="mn-member-basicinfo">
<div itemprop="streetAddress" class="mn-member-address">103 Thompson Cove</div>
<div class="mn-member-cistpost"><span itemprop="addressLocality">St. Simons Island</span>,&nbsp;<span itemprop="addressRegion">GA </span><span itemprop="postalCode">31522</span></div>
<div itemprop="telephone" class="mn-member-phone1">(912) 634-7377</div>
<div itemprop="telephone" class="mn-member-phone2">(800) 569-1955</div>
<div itemprop="faxNumber" class="mn-member-fax">(912) 638-0515 (fax)</div>
</div>
</div>
</div>
@kberov
Copy link

kberov commented Jan 28, 2015

$dom->find('div[itemprop="telephone"]')->each(sub{say shift->text});
Can you try this?
or
my @Phones = $dom->find('div[itemprop="telephone"]')->map('text')->each;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment