Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Should I use; Html Parser, table extract, Extractor

by mojotoad (Monsignor)
on Dec 21, 2005 at 22:23 UTC ( #518446=note: print w/replies, xml ) Need Help??


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

Replies are listed 'Best First'.
Re^2: Should I use; Html Parser, table extract, Extractor
by a_non_moose (Initiate) on Dec 22, 2005 at 05:31 UTC
    Thanks mojo (and gu)for the info, as I thought I was missing something (besides experience).

    Was not sure if there was more to the modules, something different with active perl under XP or some other thing I was unaware of.

    Going to digest this over the Xmas holiday after hitting the books, or taking a mental break and starting fresh "next year".

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://518446]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (6)
As of 2020-07-06 19:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?