Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
190 views
in Technique[技术] by (71.8m points)

perl - Using WWW::Mechanize to navigate forms on Amazon site

I am using WWW::Mechanize to automatically add my email address as a preferred one. After a lot of difficulty I could log into the page, but when I try to add an email address as an allowed email address it does not work. Even the link does not show up. What am I doing wrong? The link of the Amazon page is this.

My code:

use WWW::Mechanize;
use HTTP::Cookies;
use HTML::Form;
use WWW::Mechanize::Link;

my $bot = WWW::Mechanize->new();
$bot->agent_alias( 'Linux Mozilla' );

$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;
$bot->get( 'https://www.amazon.com/gp/digital/fiona/manage?ie=UTF8&*Version*=1&*entries*=0#pdocSettings' );
my @links = $bot->find_all_links( tag => "a" );

foreach (@links)
{
  print $_->text()."
" ;
}

My tamper data is this

Referer=https://www.amazon.com/gp/digital/fiona/manage?ie=UTF8&%2AVersion%2A=1&%2Aentries%2A=0

POSTDATA=sid=183-7190983-6755358&newEmail=myid%40mailhost.com

Edit: After searching I realised that WWW::Mechanize may not be able to achieve this as it lacks JavaScript support. I decided to use WWW::Scripter with the plugin. Would someone please tell me how to do it?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You found answer to your question on other post: Calling a link from perl

For future tasks similar to this one, I suggest you to do following work-around:

  • install Google Chrome (if you don't have it already)
  • navigate browser to form page you want to simulate
  • on submit button click right-click mouse button and select "Inspect element"
  • switch to "Network" tab
  • click to submit button on the form
  • see information in "Network" table, especially in "Headers" and "Response" sub-tabs.

By this kind of debugging you will find exact communication between server and browser, including cookies, referers, request methods, urls, submit data, etc.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...