perl脚本获取网络数据

前端之家收集整理的这篇文章主要介绍了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"); }

猜你在找的Perl相关文章