#! perl
use strict;
use warnings;
use LWP::Simple;
use HTML::TokeParser::Simple;
our $area ||= 1040;
my $url = "http://www.bbc.co.uk/weather/5day.shtml?id=$area";
my $html = get $url or die "Failed to get html: $!, $^E";
my $p = HTML::TokeParser::Simple->new(\$html);
while (my $t = $p->get_tag('div')){
last if
$t->get_attr('class')
and
$t->get_attr('class') eq 'display';
}
my @data;
while (my $t = $p->get_token){
last if $t->is_end_tag('div');
push @data, $t->as_is if $t->is_text;
}
# raw data
#for (0..$#data){
# print "$_: $data[$_]\n";
#}
my ($dir, $speed) = split(/\(/, $data[5]);
print <<EOP;
Sky: $data[2]
Temp: $data[3]
Wind Direction: $dir Speed: $speed
Humidity$data[11]
Pressure$data[15]
Visibility$data[17]
EOP
__DATA__
Sky: cloudy
Temp: 14
Wind Direction: SW Speed: 10
Humidity: 80,
Pressure: 1004, Rising,
Visibility: Very good
## raw data ##
0: Current Nearest Observations
1: :
2: cloudy
3: 14
4: °C
5: SW (10
6: mph
7: )
8: Relative Humidity (
9: %
10: )
11: : 80,
12: Pressure (
13: mB
14: )
15: : 1004, Rising,
16: Visibility
17: : Very good
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|