Look down to the bottom of the synopsis in the HTML:TableExtract docs for everything you need. I just ran this

#!/usr/bin/perl -w use strict; use warnings; use HTML::TableExtract qw(tree); use Data::Dumper; my $table_string = <<EOF; <table width="100%" bgcolor="#ffffff"> <tr> <td>Larry &amp; Gloria</td> <td>Mountain View</td> <td>California</td> </tr> <tr> <td><b>Tom</b></td> <td>Boulder</td> <td>Colorado</td> </tr> <tr> <td>Nathan &amp; Jenine</td> <td>Fort Collins</td> <td>Colorado</td> </tr> </table> EOF my $te = HTML::TableExtract->new(keep_html=>1); $te->parse($table_string); my $table = $te->first_table_found; my $table_tree = $table->tree; my $table_html = $table_tree->as_HTML; my $table_text = $table_tree->as_text; print Dumper($table_html),"\n"; print Dumper($table_text),"\n";

I was too lazy to dig up a table earlier, but ran across one I could paste in while I was reading so I went ahead and tested it. If you change the keep_html=>1 to keep_html=>0 then the as_HTML will strip all the markup except the table tags, and the as_text will strip out all the table tags, too.


In reply to Re: Question on extracting HTML tables with HTML::TableExtract by bitingduck
in thread Question on extracting HTML tables with HTML::TableExtract by redmage

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.