initself has asked for the wisdom of the Perl Monks concerning the following question:
The result of $touchstone should be: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"; my $touchstone = $element->look_up('_tag' => 'a')->attr_get_i('h +ref'); print $element->look_up('_tag' => 'a')->all_attr() . "\n"; } } } # Sample Code <tr valign="top"> <td width=15 bgcolor="E8F1FA"><input type="checkbox" name="checker12 +0041225" value="120041225"></td> <td width=50 bgcolor="E8F1FA"> <span class="text">Apr 27, 2006 11:29 PM</span> </td> <td width=150 bgcolor="E8F1FA"> <table width="150" border="0" cellspacing="0" cellpadding="0" clas +s="imagetable"> <tr><td> <a href="http://profile.myspace.com/index.cfm?fuseaction=user. +viewprofile&friendID=3847879"> <img src="http://myspace-646.vo.llnwd.net/00242/64/63/24245364 +6_s.jpg" align="absmiddle"> </a> <span class="text"> <a href="http://profile.myspace.com/index.cfm?fuseaction=use +r.viewprofile&friendID=3847879">JASON FEDDY</a> </span> <DIV style="width:80px;height:20px;" ID="UserDataNode2" CLASS= +"DataPoint=OnlineNow;UserID=3847879;"></div> </td></tr> </table> </td> <td width=30 bgcolor="E8F1FA">Replied </td> <td width=220 bgcolor="E8F1FA"><a class="mailtext"href="http://mail. +myspace.com/index.cfm?fuseaction=mail.readmessage&messageID=120041225 +&type=inbox&status=new&Mytoken=8727234F-137A-9B6B-2CAEC273502E282F639 +3477">Hello mate</a> </td> </tr>
as this is the url directly above the one above $subject_url . Am I misusing the function? Perhaps once you are working with a single Element, you not longer have access to the entire tree? Does $element then become the 'parent'?http://profile.myspace.com/index.cfm?fuseaction=use +r.viewprofile&friendID=3847879
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: look_up() in HTML::Element Not Traversing As Expected
by GrandFather (Saint) on Apr 29, 2006 at 03:31 UTC | |
by initself (Monk) on Apr 29, 2006 at 03:54 UTC | |
by GrandFather (Saint) on Apr 29, 2006 at 04:07 UTC | |
|
Re: look_up() in HTML::Element Not Traversing As Expected
by GrandFather (Saint) on Apr 29, 2006 at 02:26 UTC | |
by initself (Monk) on Apr 29, 2006 at 03:05 UTC |