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

I would like to write a perl script to login to this website:
http://app001.us1.darkfallonline.com/sf/fwd

My idea was simply:
use WWW::Mechanize; my $mech = WWW::Mechanize->new(); $url = "http://app001.us1.darkfallonline.com/sf/fwd"; $mech->get( $url ); $mech->set_visible( $username, $password );

However, this doesn't work. My guess is that since dump() doesn't recognize any forms or links, it doesn't know what to fill in. Also, submit() doesn't work either. The website itself seems to use js to handle everything. I have no idea how to deal with it. Help?

Replies are listed 'Best First'.
Re: Login to website (uses JS, I think)
by ikegami (Patriarch) on May 16, 2010 at 19:38 UTC

      I was able to grab Win32-IEAutomation, and it will fill in the form for me. Unfortunately, I can't get it to submit the values! I think I've covered all my bases. Any other ideas, or is it just not gonna do it?

      use Win32::IEAutomation; my $ie = Win32::IEAutomation->new( visible => 1, maximize => 1); $ie->gotoURL('http://app001.us1.darkfallonline.com/sf/fwd'); $ie->getTextBox('name:', "username")->SetValue('username'); $ie->getTextBox('name:', "password")->SetValue('password'); my @alllinks = $ie->getAllLinks(); foreach $l (@alllinks) { $l->Click(); } my @allimages = $ie->getAllImages; foreach $i (@allimages) { $i->Click(); } my @alltables = $ie->getAllTables; foreach $t (@alltables) { $t->Click(); }
        I think I need to click on a cell in the table (there's only 1), but I can't use any of the methods on my table! For example, "rows" and "tableCells" return a "Can't locate object method..." error. Any ideas what the problem is?
        Unfortunately, I can't get it to submit the values!

        What line of your program do you think that should happen?

Re: Login to website (uses JS, I think)
by Corion (Patriarch) on May 16, 2010 at 21:06 UTC

    What have you tried to verify whether the website uses Javascript or not? Usually, you can disable Javascript in your browser and then look whether the website still works or not. Or you can look at the HTML source code to see whether the pages use Javascript or not.

    Both things are basic debugging techniques that you will need when automating websites.

Re: Login to website (uses JS, I think)
by Utilitarian (Vicar) on May 17, 2010 at 07:34 UTC
    As well as the excellent advice above, I find Firefox with the Firebug extension gives me a fast way to work out what's happening on a remote site. That said using the IE or FF Mechanize modules is the correct way to resolve this.

    print "Good ",qw(night morning afternoon evening)[(localtime)[2]/6]," fellow monks."
Re: Login to website (uses JS, I think)
by paxprobellum (Initiate) on May 17, 2010 at 16:11 UTC
    After I fetch that module, I'll post back my results. Thanks for the suggestions.