It's hard to envisage what the HTML you are dealing with looks like from the code snippet. It would help us provide an answer if you could include sample HTML with the sample code. It would be even better if it were wrapped up like this:

use strict; use warnings; use HTML::TreeBuilder; my $str = do {local $/; <DATA>}; get_birthday ($str); sub get_birthday { my $content = shift; my $tree = HTML::TreeBuilder->new; $tree->parse($content); my @elements = $tree->look_down('_tag' => 'a'); for my $element (@elements) { my $class_tag = $element->attr_get_i('class') || ''; if ($class_tag eq "mailtext") { my $subject = $element->as_trimmed_text(); my $subject_url = $element->attr_get_i('href'); print "<a href='$subject_url'>$subject</a>\n"; print $element->look_up('_tag' => 'a')->all_attr() . "\n"; } } } __DATA__ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html lang="en"> <head> </head> <body> <p><a>Metalink<a class="mailtext" href='http://erewhon.com'>Erewhon</a +></a></p> </body> </html>

Interestingly this generates a 'Use of uninitialized value' warning in line 16 then prints:

<a href='http://erewhon.com'>Erewhon</a> 5/8

which looks like a stringified hash to me. That may be a clue, but without something resembling your actual HTML it's a bit hard to say.


DWIM is Perl's answer to Gödel

In reply to Re: look_up() in HTML::Element Not Traversing As Expected by GrandFather
in thread look_up() in HTML::Element Not Traversing As Expected by initself

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.