http://qs321.pair.com?node_id=518446


in reply to Should I use; Html Parser, table extract, Extractor

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