对不起,几乎所有的事情都错了。
-
你用的是
LWP::UserAgent
和
WWW::Mechanize
$mech->follow_link()
如果你使用
$browser->get()
$mech
我不知道你有要求。
-
凭据的参数不好,请参阅
the doc
你可能更想这样做:
use WWW::Mechanize;
my $mech = WWW::Mechanize->new();
$mech->credentials( '************' , '*************'); # if you do need to supply server and realms use credentials like in LWP doc
$mech->get('http://datawww2.wxc.com/kml/echo/MESH_Max_180min/');
$mech->follow_link( n => 8);
您可以检查get()的结果,并通过检查
$mech->success()
结果
if (!$mech->success()) { warn "error"; ... }
跟踪后->链接,数据可用
$mech->content()
,如果要将其保存到文件中,请使用
$mech->save_content('/path/to/a/file')
完整代码可以是:
use strict;
use WWW::Mechanize;
my $mech = WWW::Mechanize->new();
$mech->credentials( '************' , '*************'); #
$mech->get('http://datawww2.wxc.com/kml/echo/MESH_Max_180min/');
die "Error: failled to load the web page" if (!$mech->success());
$mech->follow_link( n => 8);
die "Error: failled to download content" if (!$mech->success());
$mech->save_content('/tmp/mydownloadedfile')