Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Loging into a website using javascript for login

by homer123 (Initiate)
on Sep 27, 2004 at 08:29 UTC ( [id://394099]=perlquestion: print w/replies, xml ) Need Help??

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

Hi I am a newbie wrt javascript/perl. I am trying to use perl to login to the playboy website :-) where I have a *legal* paid subscription. It uses a javascript based login and I am using WWW::Mechanize The code I am using is as follows ***********************************
use LWP::UserAgent; use HTTP::Cookies; use WWW::Mechanize; my $start_page = 'https://secure2.playboy.com/security/loginStart.do?s +c_target=cyber.playboy.com'; my $mech = WWW::Mechanize->new(); my $mech = WWW::Mechanize->new( cookie_jar => "lwpcookies.txt"); my $mech = WWW::Mechanize->new( agent=>"Mozilla/5.0 (X11; U; Linux i68 +6; en-US; rv:1.7) Gecko/20040918 Firefox/0.9.3 " ); $mech->get( $start_page ); if ($mech->success()==1) { print "Success \n"; } $mech->submit_form( form_name => 'loginForm', fields => { username => 'xxxx', password => 'xxxx', savedPWAction => 'on', submitButton => 'ENTER THE CLUB' } ); #$mech->click_button(name => 'submitButton'); #$button='submitButton'; $mech->click; $result = $mech->success(); if ($result == 1){ print "Success"; } else { print "Fail"; }
When I do use this script I get a success for the first part but I cant seem to post the username and passwrd. I get the following error msg.
Can't call method "click" on an undefined value at /usr/lib/perl5/site_perl/5.8.4/WWW/Mechanize.pm line 683.loading the page but I get an error
Can someone please help. Thank you

Replies are listed 'Best First'.
Re: Loging into a website using javascript for login
by PodMaster (Abbot) on Sep 27, 2004 at 08:46 UTC
    Hi
    • When you're new,
      use strict; use warnings; use diagnostics;
    • There is no javascript, there is only HTTP
    • use LWP::Debug qw(+);

    MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
    I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
    ** The third rule of perl club is a statement of fact: pod is sexy.

      Hi PodMaster, Thanks for the swift kick in the butt. :-) I have added strict, warning and diagnostics. I have cleaned up the really stupid mistakes that I had. I can now see it using the cookies unlike before. I was able to successfully fill in the form and retrieve the content i.e my submit_form() method returns a sucess. The content is as follows.
      <META HTTP-EQUIV="Refresh" CONTENT="0;URL=https://secure2.playboy.com/ +security/cookieGenerator.do"> <html> <body bgcolor="#000000" > </body> </html>

      This is the content I get when I use a regular browser also. So I think the code works until this point. In the regular browser it then goes to the next page which is also a https page. The link for the page is in the variable $member_gateway. I tried downloading that next but when I try that I get the same login page again.
      I did read your README. I use linux. so I wont be able to use your repository.
      Thank you for your original comments
      Here is my new code
      #!/usr/bin/perl use HTTP::Cookies; use WWW::Mechanize; use strict; use warnings; use diagnostics; use LWP::Debug qw(+); #Shows the transaction taking place my $start_page = 'https://secure2.playboy.com/security/loginStart.do?s +c_target=cyber.playboy.com'; my $mech = WWW::Mechanize->new( agent=>"Mozilla/5.0 (X11; U; Linux i68 +6; en-US; rv:1.7) Gecko/20040918 Firefox/0.9.3 " ); my $cookie_jar = HTTP::Cookies->new(file => './lwp_cookies.dat', autos +ave => 1,); #Creating a cookie jar $mech->cookie_jar($cookie_jar); #Attaching cookie jar to the user agen +t i.e $mech $mech->get( $start_page ); if ($mech->success()==1) { print "Success \n"; } $mech->submit_form( form_name => 'loginForm', fields => { username => 'xxxx', password => 'xxxx', savedPWAction => 'on', } ); if ($mech->success()==1) { print "Success \n"; } print $mech->content(); my $member_gateway='https://secure2.playboy.com/gateway/gateway.do '; $mech->get($member_gateway); print $mech->content();

      Do you have any suggestions for downloading the next page ?

        A few comments...

        If the META refresh is directing you to 'https://secure2.playboy.com/security/cookieGenerator.do', why are you get()ing 'https://secure2.playboy.com/gateway/gateway.do '?

        If you meant after hitting 'cookieGenerator.do' you are then redirected to 'gateway.do ', are you sure that trailing space is supposed to be there?

        Have you looked at HTTP::Recorder (alt.)? It could make your life a whole lot easier. :-)

            --k.


Re: Loging into a website using javascript for login
by jacques (Priest) on Sep 27, 2004 at 14:43 UTC
    Psssst.. this is a monastery. We will not help you indulge in your sins of the flesh, although Randal's swimsuit pic collector is acceptable.
Re: Loging into a website using javascript for login
by homer123 (Initiate) on Sep 28, 2004 at 03:12 UTC
    Re: Loging into a website using javascript for login
    by homer123 (Initiate) on Sep 28, 2004 at 03:13 UTC
      With the help of the perl monks I was successfully able to get a script that will help me download pics from pb website
      Here is the final script. It works for me and it comes with no guarantee it will work for you.
      A VERY SPECIAL THANKS to perl monk "kanji" for guiding this newbie.
      #!/usr/bin/perl use HTTP::Cookies; use WWW::Mechanize; use strict; use warnings; use diagnostics; use LWP::Debug qw(+); #Shows the transaction taking place use LWP::Simple; use HTTP::Message; #Used to hold the response from get() methods my $start_page = 'https://secure2.playboy.com/security/loginStart.do?s +c_target=cyber.playboy.com'; my $mech = WWW::Mechanize->new( agent=>"Mozilla/5.0 (X11; U; Linux i68 +6; en-US; rv:1.7) Gecko/20040918 Firefox/0.9.3 " ); my $cookie_jar = HTTP::Cookies->new(file => './lwp_cookies.dat', autos +ave => 1,); #Creating a cookie jar $mech->cookie_jar($cookie_jar); #Attaching cookie jar to the user agen +t i.e $mech $mech->get( $start_page ); #Check to see if the main login page is dled correctly if ($mech->success()==1) { print "Success \n"; } #Submitting your credentials my $response = $mech->submit_form( form_name => 'loginForm', fields => { username => 'xxxx', password => 'xxxx', savedPWAction => 'on', #submitButton => 'ENTER THE CLUB' } ); #Checking to see if credentials were submitted successfully if ($mech->success()==1) { print "Success \n"; } print $mech->content(); # Follow HTTP or META refreshes. #First refresh my $url=""; my $response2=HTTP::Message->new(); if ($url = $response->header('Refresh')) { $url =~ s/^\d+;url=//i; my $response2 = $mech->get($url); } #Second refresh my $response3=HTTP::Message->new(); my $url1=""; if ($url1 = $response2->header('Refresh')) { $url1 =~ s/^\d+;url=//i; my $response3 = $mech->get($url1); } #Checking to make sure what I see in the #broser is what perl is getting print $mech->get($url1); print $mech->content(); #Now the good stuff my $filename = "./1.jpg"; my $url3="http://cyber.playboy.com/members/playmates/files/2004/08/imx +/centerfolds/centerfold-PM200408A1-01-lrg.jpg"; print $mech->get($url3,":content_file" =>$filename);

      Thanks again everyone.

    Log In?
    Username:
    Password:

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

    How do I use this?Last hourOther CB clients
    Other Users?
    Others sharing their wisdom with the Monastery: (6)
    As of 2024-04-18 07:05 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found