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 ...
|