这是一个简单的抓取网页文字的脚本:
- #!/usr/bin/perl
-
use strict;
-
use LWP::UserAgent;
-
-
my $ua = new LWP::UserAgent;
-
$ua->timeout(120);
-
my $url='';
-
my $request = new HTTP::Request('GET', $url);
-
my $response = $ua->request($request);
-
my $content = $response->content();
-
print $content;
初次运行时不成功,出现了下面这个提示:
Can't locate LWP/UserAgent.pm in @INC (@INC contains: /etc/perl /usr/lib/perl5/vendor_perl/5.8.8/i686-linux /usr/lib/perl5/vendor_perl/5.8.8 /usr/lib/perl5/vendor_perl /usr/lib/perl5/site_perl/5.8.8/i686-linux /usr/lib/perl5/site_perl/5.8.8 /usr/lib/perl5/site_perl /usr/lib/perl5/5.8.8/i686-linux /usr/lib/perl5/5.8.8 /usr/local/lib/site_perl .) at ./perl_script.pl line 3.
搜索一番后,原来需要安装 libwww-perl ,于是
$ emerge libwww-perl
连带安装了22个文件。然后这个程序才运转正常。
阅读(1425) | 评论(0) | 转发(0) |