HTML-TableParser
(0.34)
this is a good module to retrive data in HTML table~~~
the following is a sample program to get weather forecast from
tw.weather.yahoo.com/tomorrow.html
and print the result to stdout.
use LWP::UserAgent;
use HTTP::Request::Common;
use HTML::TableParser;
#
# get web page tw.weather.yahoo.com/tomorrow.html
#
$ua = LWP::UserAgent->new;
$res = $ua->request(GET 'tw.weather.yahoo.com/tomorrow.html');
@content = split "\n", $res->as_string;
foreach (@content){
if(/^(民國.*)/){
print $_, "\n\n";
}
}
#
# reference
# search.cpan.org/~djerius/HTML-TablePa...
#
@reqs = (
{
id => 5.1, # id for embedded table
row => \&row, # function callback
}
);
# create parser object
$p = HTML::TableParser->new( \@reqs,
{ Decode => 0, Trim => 0, Chomp => 0 } );
$p->parse($res->as_string);
# function callbacks
sub row {
my ( $id, $line, $cols, $udata ) = @_;
print join "\t", @$cols;
print "\n";
}
macarthur - 2004-08-21T09:05:55 (permalink)
1 out of 1 found this review helpful.
Was this review helpful to you?
Yes
No

