用 perl 取回 网页
用perl 的LWP来获取url程序代码:
#!/usr/bin/perl use strict; use LWP; my $url = shift; my $agent = LWP::UserAgent->new; my $request = HTTP::Request->new(GET => $url); my $response = $agent->request($request); $response->is_success or die "$url: ", $response->message,"\n"; print $response->content;
$ ./get_url.ple http://www. > home.html
1 LWP::UserAgent->new 用来生成一个新的对像
2 HTTP::Request->new(GET => $url) 指定GET方法,传递url
返回一个对像
3 HTTP::Request生成的对像传递给 resquest() 方法
4 显示拿回的答复
[ 本帖最后由 madfrogme 于 2012-12-4 16:48 编辑 ]