Hi datarecall!

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>
**detail 1** **detail 2** **detail 3** **detail 4**
(and enclose your code with <c>...</c> tags)

In reply to Re: Toke Parser get table by wfsp
in thread Toke Parser get table by datarecall

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.