#!/usr/bin/perl use strict; use warnings; my $main_url = "http://www.bom.gov.au"; my $entry_point = "http://www.bom.gov.au/weather/vic/forecasts.shtml"; my $webpage = undef; use HTML::TokeParser; use LWP 5.65; use Mail::Send; my $browser = LWP::UserAgent->new; my $response = $browser->get( $entry_point ); if ($response->is_success) { my $text = $response->content; my $link = HTML::TokeParser->new(\$text); #look for the link to the actual Melbourne Precis Forecast while (my $token = $link->get_tag("a")) { my $url = $token->[1]{href} || "-"; my $text = $link->get_trimmed_text("/a"); $webpage = $url if ($text =~ m/Melbourne Precis Forecast/); } my $response = $browser->get($main_url . $webpage); die "Can't get $webpage -- ", $response->status_line unless $response->is_success; die "Hey, I was expecting HTML, not ",$response->content_type unless $response->content_type eq 'text/html'; my $webpage_contents = $response->content; my $pre = HTML::TokeParser->new( \$webpage_contents ); if ($pre->get_tag( "pre" )) { my $forecast = $pre->get_text; my $msg = new Mail::Send Subject=>"Today's Forecast", To=>'YOUREMAIL@YOURADDRESS.com.au', # cc=>'', ; my $fh = $msg->open; print $fh "$forecast"; $fh->close; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Meteorology::Australia
by zentara (Cardinal) on Sep 13, 2002 at 15:28 UTC | |
|
Re: Meteorology::Australia
by quinkan (Monk) on Sep 20, 2002 at 05:24 UTC | |
by greenFox (Vicar) on Sep 20, 2002 at 06:59 UTC |