- 论坛徽章:
- 0
|
#! /usr/bin/perl -s
#查询天气预报的脚本,只取今天和明天的天气预报
use LWP::Simple;
use strict;
use Encode;
use HTML::TableExtract;
use DBI;
#binmode(STDOUT, ':encoding(gb2312)');
#消取输出缓冲
$| = 1;
my $html=get("http://www.weather.com.cn/html/weather/101010100.shtml");
my $tree = HTML::TableExtract->new( attribs => { class => 'yuBaoTable' } );
$tree->parse($html);
my $i=0;
my $msg="";
my $m="";
$| = 1;
foreach my $ts ($tree->tables) {
if ($i<2){
print ".";
print " Complete!\n" if ($i == 1);
sleep(1);
foreach my $row ($ts->rows) {
$msg=join(',', @$row);
$msg = encode("gb2312", $msg);
#print " ", join(' ', @$row),"\n";
#print "$msg\n";
my @aa=split(/,/,$msg);
foreach my $item(@aa){
if ($item){
$m=$m.$item.";";
$m=~s/\s//g;
}
}
#print "$aa[0]\n$aa[1]\n$aa[2]\n$aa[3]\n";
}
$i++;
}
}
$m=~tr/;/\n/s;
print "$m\n";
还可以利用短信猫,将信息发到手机上。呵呵,我就是这么干的,免费的天气预报! |
|