Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

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

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...