1.加载LWP::Simple
use LWP::simple;
2.抓取网页,失败返回undef
$content = get 'http://www.baidu.com';
die "get nothing!\n" unless defined $content;
3.抓取头部,依次为Content-Type,Content-Length,Last-Modified,Expires,Server;失败返回空数组,如果返回值为变量,则成功返回TRUE。
my @content = head 'http://www.baidu.com';
4.获取并打印一个网页到默认的输出句柄。如果请求失败,则打印状态码和消息到STDERR.
$code = getprint 'http://www.baidu.com';
5.抓取网页并存储。返回响应码。
$code = getstore ('http://www.baidu.com','baidu.html');
6.抓取并存储网页。和getstore的区别在于,会加上If-Modified-Since头域,并检查 Content-Length头部。
$code = mirror ('http://gimg.baidu.com/img/gs.gif','gs.gif');
7.getprint(), getstore() or mirror()所获得的状态码,可以被HTTP::Status使用。
8:可以不加载某一部分,例如:
use LWP::Simple qw(!head);
当需要使用时如下调用:
LWP::Simple::head($url);