2012-05-17 49 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