This assumes there is only one table with class="details".
#!/usr/bin/perl use warnings; use strict; use HTML::TokeParser; my $html = do{local $/;<DATA>}; my $p = HTML::TokeParser->new(\$html); # find the start of the table while (my $t = $p->get_token){ last if( $t->[0] eq q{S} and $t->[1] eq q{table} and ${$t->[2]}{class}, and ${$t->[2]}{class} eq q{details} ); } my ($in_td); while (my $t = $p->get_token){ # quit loop when we find the end of the table last if( $t->[0] eq q{E} and $t->[1] eq q{table} ); $in_td++, next if $t->[0] eq q{S} and $t->[1] eq q{td}; $in_td--, next if $t->[0] eq q{E} and $t->[1] eq q{td}; next unless $in_td; # if we are here we must be in a td tag if ($t->[0] eq q{T}){ print qq{**$t->[1]**\n}; } } __DATA__ <html> <head> <title>table</title> </head> <body> <table class="details"> <tr> <td>detail 1</td> <td>detail 2</td> </tr> <tr> <td>detail 3</td> <td>detail 4</td> </tr> </table> </body> </html>
(and enclose your code with <c>...</c> tags)**detail 1** **detail 2** **detail 3** **detail 4**
In reply to Re: Toke Parser get table
by wfsp
in thread Toke Parser get table
by datarecall
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |