Perl WWW::机械化凭据
我想使用WWW::Mechanize搜索网站内容,但要做到这一点,首先我必须使用注册的用户名和密码登录,这是我无法使用此代码完成的。必须更改哪些内容才能成功提交表单。谢谢Perl WWW::机械化凭据,perl,Perl,我想使用WWW::Mechanize搜索网站内容,但要做到这一点,首先我必须使用注册的用户名和密码登录,这是我无法使用此代码完成的。必须更改哪些内容才能成功提交表单。谢谢 use strict; use warnings; use WWW::Mechanize; my $username = "username"; my $password = "password"; my $cookie_jar; my $url = "http://www.albumartexchange.com/for
use strict;
use warnings;
use WWW::Mechanize;
my $username = "username";
my $password = "password";
my $cookie_jar;
my $url = "http://www.albumartexchange.com/forums/ucp.php?mode=login";
my $mech = WWW::Mechanize->new( cookie_jar => $cookie_jar );
$mech->credentials($username, $password);
$mech->get($url);
$mech->success() or die "Failed";
$mech->submit_form(
form_number => 4,
);
die "Submit failed" unless $mech->success;
$mech->save_content('log.txt');
更新:
use strict;
use warnings;
use WWW::Mechanize;
my $cookie_jar;
my $mech = WWW::Mechanize->new( cookie_jar => $cookie_jar );
$mech->get( 'http://www.albumartexchange.com/forums/ucp.php?mode=login' );
$mech->submit_form(
form_number => 4,
fields => {
'username'
=> 'some_username',
'password'
=> 'some_password',
}
);
$mech->save_content('log.txt');
该页面不使用HTTP身份验证,这正是凭据的用途。只需使用Mech填写用户名和密码表单字段并提交登录表单。此处不需要凭据。只需使用:
$mech->submit_form(
form_number => 4,
fields => {
username => $user,
password => $pass,
},
);
当然,不要忘记将用户名和密码更改为目标页面的实际字段名。你的意思是像我发布的更新一样,因为我仍然无法登录。顺便问一下,你为什么使用$cookie\u jar?默认情况下,Mechanize中会启用Cookie内容,因此我确信您不需要在此处使用它。