Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
Greetings, esteemed monks!

I'm running into a wall with trying to have my Mech program log into the following site: http://www.nyscr.org/Login.aspx .

I think it's because it's doing something tricky with the User Type field. It's not a typical select, it's something weird. The response content I get back is what I would get if I did not specify a User Type, ie the red '* required' text is visible next to the User Type box.

Here is my code:
#!/usr/bin/perl -- use strict; use warnings; use LWP::UserAgent; use WWW::Mechanize; use Readonly; use HTML::TreeBuilder; #use HTML::Element qw(Table); use HTML::TableExtract;# qw(tree); use HTML::Encoding 'encoding_from_http_message'; use Encode; use File::Slurp; use Date::Manip; Readonly::Scalar my $url => 'http://www.nyscr.org/Login.aspx'; Readonly::Scalar my $un => 'email@firm.com'; Readonly::Scalar my $pw =>'IheartPERL'; my $mech = WWW::Mechanize->new( agent => 'Mozilla/5.0 (Windows NT 6.1; + WOW64; rv:6.0.2) Gecko/20100101 Firefox/6.0.2' ); $mech->get($url); #The user name input is ctl00$ContentPlaceHolder1$ctl00$txtUserName #PW field is ctl00$ContentPlaceHolder1$ctl00$txtPassword #"User Type field (actually a select but think I can treat as a regula +r input) my $response = $mech->submit_form( form_number => 1, fields => { 'ctl00$ContentPlaceHolder1$ctl00$rcbusertype_Input' => "Su +bscriber", 'ctl00$ContentPlaceHolder1$ctl00$txtUserName' => $un, 'ctl00$ContentPlaceHolder1$ctl00$txtPassword' => $pw, } ); if ($response->is_success) { print $response->decoded_content; # or whatever $mech->save_content('resp.html'); } else { die $response->status_line; }
I have also tried
$mech->set_fields( 'ctl00$ContentPlaceHolder1$ctl00$rcbusertype_Input' => "Su +bscriber", 'ctl00$ContentPlaceHolder1$ctl00$txtUserName' => $un, 'ctl00$ContentPlaceHolder1$ctl00$txtPassword' => $pw, ); my $response = $mech->click_button( name => 'ctl00$ContentPlaceHolder1 +$ctl00$LoginButton', x=>26, y=>10);
(the 26,10 x,y coords are from an examination of the headers using livehttpheaders) I've tried including the ctl00_ContentPlaceHolder1_ctl00_rcbusertype_ClientState parameter as well as some other tomfoolery.

I'm hoping the presence of js on the page isn't going to preclude me from using Mech, just that I have to figure out what's going on, and, if necessary, cut out the middleman.

Thanks!


I like computer programming because it's like Legos for the mind.

In reply to Help with logging in to a tricky ASP web form with JavaScript using WWW::Mechanize by OfficeLinebacker

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others surveying the Monastery: (16)
    As of 2015-07-02 18:31 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









      Results (44 votes), past polls