coderman9 has asked for the wisdom of the Perl Monks concerning the following question:
So, I'm trying to automate the process of buying something on amazon (its part of a larger project). To do that I'm using WWW::Mechanize. But I keep getting this error "Can't call method "header" on an undefined value at /usr/local/share/perl5/WWW/Mechanize.pm line 2566." No clue what's going on, but here's my code. I looked at line 2566, but am not sure what is happening, since I'm not using that method (at least I don't think I am).
use strict; use WWW::Mechanize; use Crypt::SSLeay; #initialization my $loginPage="https://www.amazon.com/ap/signin?_encoding=UTF8&openid. +assoc_handle=amazon_checkout_us&openid.claimed_id=http%3A%2F%2Fspecs. +openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.identity=http%3A%2 +F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.mode=che +ckid_setup&openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0&openi +d.ns.pape=http%3A%2F%2Fspecs.openid.net%2Fextensions%2Fpape%2F1.0&ope +nid.pape.max_auth_age=0&openid.return_to=https%3A%2F%2Fwww.amazon.com +%2Fgp%2Fbuy%2Fsignin%2Fhandlers%2Fcontinue.html%3Fie%3DUTF8%26eGCApp% +3D%26hasWorkingJavascript%3D0%26isEGCOrder%3D0%26oldCustomerId%3D%26o +ldPurchaseId%3D%26preInitiateCustomerId%3D%26purchaseInProgress%3D%26 +siteDesign%3D&pageId=amazon_checkout_us&showRmrMe=0&siteState=isRegul +arCheckout.1|IMBMsgs.|isRedirect.0"; my $addToCart="http://www.amazon.com/gp/product/handle-buy-box/ref=dp_ +start-bbf_1_glance"; #target my $target="http://www.amazon.com/Effective-Java-Edition-Joshua-Bloch/ +dp/0321356683/ref=sr_1_2?ie=UTF8&qid=1386465356&sr=8-2&keywords=java" +; my $fileToWrite; #login my $email="something"; my $pass="somethingelse"; #browser object my $mech=WWW::Mechanize->new(autocheck=>'1'); $mech->add_header(agent=>'Mozilla/5.0 (X11; Linux i686; rv:21.0) Gecko +/20100101 Firefox/21.0'); $mech->cookie_jar ( HTTP::Cookies->new ( 'file'=>'/mnt/sdb1/porteus/cookies/amazonSessionId.lwp', 'autosave'=>1, ) ); #main part, with dumping of statuses and content $mech->get($target); file("/file1.txt"); amazonSubmit($target); file("/file2.txt"); amazonSubmit($addToCart); file("/file3.txt"); login(); file("/file4.txt"); #subroutines sub amazonSubmit() {$mech->post(@_[0], [ 'type'=>'submit', 'value'=>'Go', 'class'=>'nav-submit-input', 'title'=>'Go', ] ); } sub login() { $mech->get($loginPage); $mech->set_visible($email, $pass); $mech->click_button('value'=>'"Sign in using our secure server"'); } sub file () { $fileToWrite=@_[0]; open (FILEHANDLE, ">\$fileToWrite"); print FILEHANDLE "$mech->content\n"; print FILEHANDLE "$mech->status"; close (FILEHANDLE); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Error when using WWW::Mechanize
by kschwab (Vicar) on Dec 15, 2013 at 15:16 UTC | |
by coderman9 (Initiate) on Dec 15, 2013 at 21:34 UTC | |
|
Re: Error when using WWW::Mechanize
by Anonymous Monk on Dec 15, 2013 at 06:36 UTC | |
by coderman9 (Initiate) on Dec 15, 2013 at 21:28 UTC | |
|
Re: Error when using WWW::Mechanize
by Anonymous Monk on Feb 05, 2019 at 10:00 UTC |