Ben,

Personally, when dealing with tabular data, I prefer to use
HTML::TableExtract. Here's a little program I whipped up to grab the current
temperature (in degrees F):

# ---

use HTML::TableExtract;
use Data::Dumper;

open( FILE, 'NOAA.html' ) or die "cannot open file: $!";
my $data = do { local $/; <FILE> }; 
close( FILE );

my $parser = HTML::TableExtract->new( depth => 2, count => 0 );
$parser->parse( $data );

my $state = $parser->first_table_state_found;
my $row   = ( $state->rows )[ 0 ];
my $temp  = $row->[ 0 ];
$temp     =~ /(-?\d+).F/s;
$temp     = $1;

print "The temperature is $temp degrees F\n";

# ---

The key here is finding the right depth and count. Check the docs for more
details.

-Brian

(NB: you may wish to test the code more than I have -- it seemed to work on
this page:
http://www.crh.noaa.gov/forecasts/CAZ041.php?warncounty=CAC037&city=Beverly+
Hills )

> -----Original Message-----
> From: Ben Ostrowsky [mailto:[EMAIL PROTECTED]
> Sent: Monday, January 26, 2004 5:47 PM
> To: [EMAIL PROTECTED]
> Subject: HTML::Parser walkthrough?
> 
> I'm trying to build a script that will go to a NOAA web page, find the
> current temperature, and return just that information.
> 
> If the first TABLE in the document is TABLE[0], then the data I want is, I
> think, at:
> 
> HTML > BODY > TABLE[3] > TR[7] > TD[1]
> 
> But how can I use Perl to get the contents of that TD?  I don't understand
> the HTML::Parser manpage.
> 
> Ben


http://www.gordano.com - Messaging for educators.

Reply via email to