Perl结合飞信发送免费的天气预报信息
2011-07-22 16:42
579 查看
每天在公司上班,打开QQ的同时,就顺便看了一下今天的天气情况。当时就在想,可不可以用perl来解析这个html页面,抽取其中必要的elements,然后透过第三方的飞信将该消息发送给自己,不就可以了么。说干就干,就写了这么一段代码,算法不是特别好,参考了某位网友的处理方法,但又有区别。
获取天气预报的页面地址,我用了这个address
完整的code如下:(调试了一天,妈妈的)
此支perl程序,仅仅抽取了天气预报详情页面的这几个值:
1) 日期
2) 实际天气情况
3)当天的气温
其他的就没有弄了,情况类似。
附:linux下配置飞信的方法
下载机器人支持库
注:我的系统是64位的,但是如果下载了64位的版本,ms有问题,32位的就OK
另外,linux用户,请不要把支持库中的 lib* 复制到 /usr/lib 下,因为发行版本不同,可能会覆盖您机器中的核心库,导致严重系统问题。您可以把库解压到主程序的相同目录,然后以 LD_LIBRARY_PATH=. ./fetion 来运行)
详细介绍见这个页面
获取天气预报的页面地址,我用了这个address
http://qq.ip138.com/weather/zhejiang/HangZhou.htm
完整的code如下:(调试了一天,妈妈的)
#!/usr/bin/perl -w use strict; #utf8一定要加,否则出现乱码 use utf8; use LWP::Simple; use 5.010; my $url = shift || "http://qq.ip138.com/weather/zhejiang/HangZhou.htm"; my $content = get $url; my @url = split /\n/,$content; my $path = "/root/lib"; my $fetion = "/root/lib/fetion"; &get_weather(\@url); system(qq{LD_LIBRARY_PATH=$path $fetion --mobile=12345678901 --pwd='123456' --to=123456 --exit-on-verifycode=1 --file-utf8=/root/weather.txt --msg-type=1}); sub get_weather($) { my ( $weather ) = @_; my ( $count,$i ) = ( 0,0 ); while ( $i < scalar(@$weather) ) { next unless @$weather[$i++] =~ /日期/; $i += 1; open my $file,'>>','/root/weather.txt' or die "$!\n"; if ( -s '/root/weather.txt' > 0 ) { system("cat /dev/null >/root/weather.txt"); } while ( $count < 1 ) { @$weather[$i++] =~ /(?:.*)\>(?<name1>.*?)\<\/td\>/; $count ++; say $file "$+{name1}\t"; } say $file "\n"; $i += 9; $count = 0; while ( $count < 1 ) { @$weather[$i++] =~ /.*\>(?<name2>.*)\<\/td\>/; $count ++; say $file "$+{name2}\t"; } say $file "\n"; $i += 9; $count = 0; while ( $count < 1 ) { @$weather[$i++] =~ /(?:.*)\>(?<name3>.*?)\<\/td\>/; $count ++; say $file "$+{name3}\t"; } close $file; last; } }
此支perl程序,仅仅抽取了天气预报详情页面的这几个值:
1) 日期
2) 实际天气情况
3)当天的气温
其他的就没有弄了,情况类似。
附:linux下配置飞信的方法
下载机器人支持库
http://www.it-adv.net/fetion/linuxso_20101113.rar
注:我的系统是64位的,但是如果下载了64位的版本,ms有问题,32位的就OK
另外,linux用户,请不要把支持库中的 lib* 复制到 /usr/lib 下,因为发行版本不同,可能会覆盖您机器中的核心库,导致严重系统问题。您可以把库解压到主程序的相同目录,然后以 LD_LIBRARY_PATH=. ./fetion 来运行)
详细介绍见这个页面
http://bbs.it-adv.net/viewthread.php?tid=1081&extra=page%3D1本文出自 “BSDerの-专注于开源领域” 博客,请务必保留此出处http://hellosa.blog.51cto.com/2698675/620743
相关文章推荐
- perl获取天气预报信息结合139邮箱推送到手机端
- 使用ASP发送飞信的免费短信
- pyhthon 利用爬虫结合阿里大于短信接口实现短信发送天气预报
- php结合飞信 免费天气预报短信
- 使用ASP发送飞信的免费短信
- c#用飞信免费发送短信
- Python发送天气预报信息到手机
- 使用ASP发送飞信的免费短信
- C#通过飞信WebService发送免费短信
- Python发送天气预报信息到手机
- java调用飞信接口免费短信发送到对方手机
- 使用ASP发送飞信的免费短信
- linux命令行下用Fetion飞信发送免费短信
- MSSQL/WMI/PowerShell结合篇(四)PowerShell发送微信信息
- php结合飞信 免费天气预报短信
- 使用ASP发送飞信的免费短信
- 利用飞信免费发送短信的网页插件---FetionWidget-1.0-beta
- 【转载】完全免费的手机短信天气预报与免费发送祝福短信(转自X-Force)
- 发送飞信免费短信API
- C#通过飞信WebService发送免费短信