in reply to How to find an xpath from an web page

Please review How (Not) To Ask A Question. I think this is xpath
#!/usr/bin/perl -- use strict; use warnings; use HTML::TreeBuilder; { my $tree = HTML::TreeBuilder->new(); $tree->look_down(qw!_tag body!)->push_content( [ ul => map [ 'li', $_ ], qw(Peaches Apples Pears Mangos) ], [ table => map [ tr => [ td => $_ ] ], 1 .. 3 ], ); print $tree->as_HTML( '', ' ' ); sub HTML::Element::addressx { return join( '/', '/', # // ROOT reverse( # so it starts at the top map { my $n = $_->pindex() || '0'; my $t = $_->tag; $t . '['. $n .']' } # so that root's undef -> '0' $_[0], # self and... $_[0]->lineage ) ); } ## end sub HTML::Element::addressx for my $td ( $tree->look_down( _tag => 'td' ) ) { print $td->addressx, "\n"; } ## end for my $td ( $tree->look_down...) $tree->delete; undef $tree; } __END__ <html> <head> </head> <body> <ul> <li>Peaches<li>Apples<li>Pears<li>Mangos</ul> <table> <tr> <td>1</td> </tr> <tr> <td>2</td> </tr> <tr> <td>3</td> </tr> </table> </body> </html>
//html[0]/body[1]/table[1]/tr[0]/td[0] //html[0]/body[1]/table[1]/tr[1]/td[0] //html[0]/body[1]/table[1]/tr[2]/td[0]