2012-05-17 48 views
1

我正在使用WWW:机械化尝试登录到站点。无法使用www登录到站点:机械化

代码

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(); 

但是它没有被登录到该网站。我究竟做错了什么。该网站重定向并说,请启用Cookie继续。我怎么做 。

enter image description here

回答

5

尝试把此块你才把。

$mech->cookie_jar(
     HTTP::Cookies->new(
      file   => "cookies.txt", 
      autosave  => 1, 
      ignore_discard => 1, 
    ) 
); 

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; 
+0

这并不奏效。它仍然显示需要启用cookie。 – user1092042

+0

你试过新编辑过的块吗?编辑:检查qpassword部分。在网站的来源中似乎没有任何'qpassword'。但我认为这只是一个转移错字? – iCanHasFay

+0

是的。那也不行。我不知道为什么。是。我把qpassword输入密码。 – user1092042