perl脚本获取网络数据

通过perl脚本调用url接口获取数据,可进行远程数据访问,相当方便:

#!/usr/bin/perl
#if error for simple please command 'cpan LWP::Simple' in shell

use strict;
use warnings;
use LWP::UserAgent;
use LWP::Simple;
use utf8;

use Encode;

binmode(STDIN,':encoding(GB2312)'); binmode(STDOUT,':encoding(GB2312)'); binmode(STDERR,':encoding(GB2312)'); my $arg0 = $ARGV[0]; my $arg1 = $ARGV[1]; my $url = "http://ip/index.htm?blah=$arg0&gaga=$arg1"; my $ua = LWP::UserAgent-> new( env_proxy => 1,keep_alive => 1,timeout => 5 ); my $response = $ua-> get($url); if ($response-> is_success) { my $data = $response-> content(); print("the data is $data\n"); } else { print("can not get the data\n"); }

相关文章

1. 如何去重 #!/usr/bin/perl use strict; my %hash; while(...
最近写了一个perl脚本,实现的功能是将表格中其中两列的数据...
表的数据字典格式如下:如果手动写MySQL建表语句,确认麻烦,...
巡检类工作经常会出具日报,最近在原有日报的基础上又新增了...
在实际生产环境中,常常需要从后台日志中截取报文,报文的形...
最近写的一个perl程序,通过关键词匹配统计其出现的频率,让...