Here's a complete guess as to what you mean.

You're looking for something like a TD element with the class "important" and you want the text content of the TD preceding it.

This would do it:

#!/usr/bin/perl use strict; use warnings; use HTML::TreeBuilder; my $tree = HTML::TreeBuilder->new; # empty tree $tree->parse_file( \*DATA ); my $matching_td = $tree->look_down( "_tag", "td", "class", "important" ); my $td_before = $matching_td->left(); print $td_before->as_text(); __DATA__ <html> <head> <title>Untitled</title> </head> <body> <table> <tr> <td> foo </td> <td class="important"> </td> </tr> <tr> <td> bar </td> <td class="boring"> </td> </tr> </table> </body> </html>

The above code prints "foo" because that's the text content of the TD immediately preceding the one with the right attribute. Though as GrandFather says, we have no idea what you really mean.



Nobody says perl looks like line-noise any more
kids today don't know what line-noise IS ...

In reply to Re: HTML::TreeBuilder documentation tests trouble by Cody Pendant
in thread HTML::TreeBuilder documentation tests trouble by spx2

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.