Listing 1.
get_weather: A Perl script that fetches the current weather report.
Lincoln Stein

CGI Programming: The LWP Library
The Perl Journal, Winter 1996
 
01 #!/usr/bin/perl 
02 # File: get_weather 
03 
04 use LWP::UserAgent; 
05 use HTML::Parse; 
06 use HTML::FormatText; 
07 
08 # options 
09 $CITY = shift || 'BOS'; 
10 $URL = 'http://www.nnic.noaa.gov/cgi-bin/netcast.do-it'; 
11 $OPTIONS =
     'city=on&area=Local+Forecast&match=Strong+Match&html=text+only+format'; 
12 
13 $agent = new LWP::UserAgent; 
14 $request = new HTTP::Request('GET', "$URL?state=$CITY&$OPTIONS"); 
15 $response = $agent->request($request); 
16 die "Couldn't get URL. Status code = ", $response->code 
17 unless $response->isSuccess; 
18 
19 $parse_tree = parse_html($response->content); 
20 $formatter = new HTML::FormatText; 
21 @lines = split("\n",$formatter->format($parse_tree)); 
22 foreach (@lines) { 
23     print $_, "\n" if /^\s*[-]+\w/../^\s*[-]+$/; 
24 }