Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HTML::TreeBuilder question

Status
Not open for further replies.

eterry28

Programmer
Aug 12, 2004
2
US
Hey gang, I have a question about HTML::TreeBuilder.

Given the following code:
use HTML::TreeBuilder;
my $root = HTML::TreeBuilder->new_from_file( "product.html" );
$root->eof();
$root->dump;

I get the following dump:
...
<tr> @0.1.1.0.1.0.10
<td align="right"> @0.1.1.0.1.0.10.0
<strong> @0.1.1.0.1.0.10.0.0
"Add'l Return Info:"
<td> @0.1.1.0.1.0.10.1
"Past Exchange-Call Antec 510-770-1200"
<tr> @0.1.1.0.1.0.11
<td align="right"> @0.1.1.0.1.0.11.0
<strong> @0.1.1.0.1.0.11.0.0
"Mfr. Warranty:"
<td> @0.1.1.0.1.0.11.1
"3 YEARS"
...

Ok here's the question. Is there a way to use the (@0.1.1.0.1.0.11.0.0) notation to go to a specific node and get the information there?
 
Hi eterry28

TreeBuilder inherits a lot of its traversal routines from HTML::Element. I think what you are looking for is

my $node = $root->address('0.1.1.0.1.0.11.0.0');
print $node->as_text;

address will return an undef if there is no node

caveat:
You may not be able to port this to other platforms well since hashes usually aren't stored in any meaningful manner. i.e. what is at this node on this system may be at another somewhere else entirely.

You should check out HTML::Element for a better solution...

Hope this helps
hgfawkes
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top