Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

web mechanize issue with javascript...

by perlknight (Pilgrim)
on May 01, 2006 at 03:24 UTC ( [id://546625]=perlquestion: print w/replies, xml ) Need Help??

perlknight has asked for the wisdom of the Perl Monks concerning the following question:

All, I am trying to automate upload of pics to "http://www1.snapfish.com/welcomenphu". But I am having issue with javascript. First cut at automating the login with web mechanize:
use WWW::Mechanize; #use HTML::TokenParser; my $agent = WWW::Mechanize->new; $agent->get("http://www1.snapfish.com/welcomenphu"); $agent->form("form1"); $agent->field("emailaddress","me@mykingdom"); $agent->field("password","123"); $agent->click(); print "$agent->{content}";
The next page, if I login successfully will have my photo album dir. However, this is not the case; I dump out the output in html format and used firefox to view it. It prompts me that the account already exists and asked if I want to create another account or click the login button. When I click on the login button, it brings me to the page where my album dir is located. I am thinking it's a javascript issue. Any idea? Thanks.

Replies are listed 'Best First'.
Re: web mechanize issue with javascript...
by dragonchild (Archbishop) on May 01, 2006 at 03:43 UTC
    WWW::Mechanize doesn't do Javascript. Now, the IE Mechanize might because it's using OLE to actually run an IE instance. But, the WWW::Mechanize doesn't do JS. Of course, patches are always welcome.

    My criteria for good software:
    1. Does it work?
    2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?
      Yes, Win32::IE::Mechanize does do Javascript. It behaves a little oddly: code like document.write(...); includes both the original Javascript, as the generated result, in the "source". So it can't be a true compatible replacement for WWW::Mechanize... Once you take that behaviour into account, it works out very well.

      An obvious limitation is that it only works on Windows, and you need an install of MSIE. But, given the former, the latter comes as a given. ;-)

Re: web mechanize issue with javascript...
by perrin (Chancellor) on May 01, 2006 at 05:21 UTC
    It sounds like you're jumping to conclusions. What reason do you have for thinking it's javascript? If you turn off javascript in Firefox, can you access the page you're trying to get to? More likely, you're just hitting the wrong form or missing a field. You can see the exact data sent by Firefox with the LiveHTTPHeaders extension.
Re: web mechanize issue with javascript...
by crashtest (Curate) on May 01, 2006 at 05:00 UTC

    A quick look at http://www1.snapfish.com/welcomenphu shows that the login information is posted via https. Do you have OpenSSL installed, or have Perl set up for HTTPS some other way?

    I suspect the SSL is your problem, not JavaScript in this case (but I didn't look too closely).

    Hope this helps.

Re: web mechanize issue with javascript...
by Anonymous Monk on May 01, 2006 at 03:52 UTC
Re: web mechanize issue with javascript...
by teabag (Pilgrim) on May 03, 2006 at 09:20 UTC
    Hey perlknight,

    I had a similar problem recently. I had to deal with javascript on a page and I wanted to use WWW::Mechanize.

    Checking the monastery gave me some help, but didn't give me a specific answer, just pointers towards a long and winding road.

    Browsing though CPAN I stumbled upon Win32::IEAutomation, web application automation using Internet Explorer.

    Now I don't know if your code should run on windows or an other platform. Since Win32::IEAutomation uses Win32::OLE to create automation object for IE, it's only usefull on windows. But I had a script whipped up in a couple of minutes.

    from the docs:
    It drives internet explorer using its DOM properties and methods. The module allows user to interact with web page controls like links, buttons, radios, checkbox, text fields etc. It also supports frames, popup window and interaction with javascript dialogs like security alert, confirmation, warning dialog etc.

    There's no ppm for it at activestate, but if you download it, untar it and just put the folder in your Win32 folder in your perl directory it will function perfectly.

    Good luck,


    teabag
    Blessed is the end user who expects nothing, for he/she will not be disappointed.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://546625]
Approved by graff
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2024-04-16 18:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found