in reply to Re^2: How to fetch table element from a site into data
in thread How to fetch table element from a site into data
You almost got it(!), but you've captured the html content into $a, and then used $te->parse($html_string);.
Try the following (based on the HTML::TableExtract scripting example):
use Modern::Perl; use WWW::Mechanize; use HTML::TableExtract; my $mech = WWW::Mechanize->new(); $mech->get('http://www.w3schools.com/sql/default.asp'); my $html_string = $mech->content(); my $te = HTML::TableExtract->new( headers => [ ( 'Company', 'Country' +) ] ); $te->parse($html_string); foreach my $ts ( $te->tables ) { print "Table (", join( ',', $ts->coords ), "):\n"; foreach my $row ( $ts->rows ) { print join( ',', @$row ), "\n"; } }
Output
Table (0,0): Island Trading,UK Galería del gastrónomo,Spain Laughing Bacchus Wine Cellars,Canada Paris spécialités,France Simons bistro,Denmark Wolski Zajazd,Poland
Hope this helps!
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^4: How to fetch table element from a site into data
by Anonymous Monk on Aug 12, 2012 at 05:07 UTC | |
by Kenosis (Priest) on Aug 12, 2012 at 06:44 UTC |
In Section
Seekers of Perl Wisdom