Hi there !moose,

A couple of observations regarding two of the modules being mentioned, HTML::TableExtract and HTML::ElementTable:

These play much better together than they used to in times past. So now you can use HTML::TableExtract to automatically return an HTML::ElementTable structure if you want, thereby bypassing the HTML::Parser code if you so desire:

use HTML::TableExtract qw(tree); my $te = HTML::TableExtract->new(); my $table = $te->first_table_found(); # $table is an HTML::ElementTable structure # ... maybe edit the tree structure here print $table->as_HTML;

Also, since you're fairly new to both modules, I'll point out that the normal operation of HTML::TableExtract is to return the raw text, stripped of all html. It is very similar in structure to the above code:

use HTML::TableExtract; my $te = HTML::TableExtract->new(); my $table = $te->first_table_found(); foreach my $row ($table->rows) { foreach my $cell (@$row) { ... maybe edit text } }

Alternatively, you can preserve the HTML in each cell as text:

use HTML::TableExtract; my $te = HTML::TableExtract->new(keep_html => 1); my $table = $te->first_table_found(); foreach my $row ($table->rows) { foreach my $cell (@$row) { ... maybe edit html text } }

Another option for H::TE that you might find useful is the 'decode' option for when you're extracting in text mode (without keeping the html). When this is disabled (decode => 0 ... it's enabled by default) then your codes for things such as 'nbsp' are not translated into their actual character -- that might make it easier for search and replace type operations.

Cheers,
Matt


In reply to Re: Should I use; Html Parser, table extract, Extractor by mojotoad
in thread Should I use; Html Parser, table extract, Extractor by a_non_moose

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.