我正在使用WWW:Mechanize尝试登录网站.
码
use WWW::Mechanize;
my $mech = WWW::Mechanize->new();
$mech->get("https://www.amazon.com/gp/css/homepage.html/");
$mech->submit_form(
form_name => 'yaSignIn',
fields => {
email => 'email',
qpassword=> 'pass'
}
);
print $mech->content();
Run Code Online (Sandbox Code Playgroud)
但是它没有登录到网站.我究竟做错了什么.该网站重定向并说,请启用cookie继续.我怎么做 .

在你获得之前尝试放置这个块.
$mech->cookie_jar(
HTTP::Cookies->new(
file => "cookies.txt",
autosave => 1,
ignore_discard => 1,
)
);
Run Code Online (Sandbox Code Playgroud)
SuperEdit2:我自己尝试了这个,它似乎有效.试一试.(将表格编号更改为3并添加代理别名)
use strict;
use warnings;
use WWW::Mechanize;
# Create a new instance of Mechanize
my $bot = WWW::Mechanize->new();
$bot->agent_alias( 'Linux Mozilla' );
# Create a cookie jar for the login credentials
$bot->cookie_jar(
HTTP::Cookies->new(
file => "cookies.txt",
autosave => 1,
ignore_discard => 1,
)
);
# Connect to the login page
my $response = $bot->get( 'https://www.amazon.com/gp/css/homepage.html/' );
# Get the login form. You might need to change the number.
$bot->form_number(3);
# Enter the login credentials.
$bot->field( email => 'email' );
$bot->field( password => 'pass' );
$response = $bot->click();
print $response->decoded_content;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
434 次 |
| 最近记录: |