in reply to look_up() in HTML::Element Not Traversing As Expected
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: look_up() in HTML::Element Not Traversing As Expected
by initself (Monk) on Apr 29, 2006 at 03:05 UTC |