|
#!/usr/bin/perl
|
|
# From Issue #4 of The Perl Journal
|
|
use LWP::UserAgent;
|
|
use HTML::Parse;
|
|
use HTML::FormatText;
|
|
# options
|
|
$CITY = shift || 'BOS';
|
|
$URL = 'http://www.nnic.noaa.gov/cgi-bin/netcast.do-it';
|
|
$OPTIONS = 'city=on&area=Local+Forecast&match=Strong+Match&html=text+o\
|
|
nly+format';
|
|
$agent = new LWP::UserAgent;
|
|
$request = new HTTP::Request('GET',"$URL?state=$CITY&$OPTIONS");
|
|
$response = $agent->request($request);
|
|
die "Couldn't get URL. Status code = ",$response->code
|
|
unless $response->isSuccess;
|
|
$parse_tree = parse_html($response->content);
|
|
$formatter = new HTML::FormatText;
|
|
@lines = split("\n",$formatter->format($parse_tree));
|
|
foreach (@lines) {
|
|
print $_,"\n" if /^\s*[-]+\w/../^\s*[-]+$/;
|
|
}
|