in reply to Loging into a website using javascript for login

Hi

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.

Replies are listed 'Best First'.
Re^2: Loging into a website using javascript for login
by homer123 (Initiate) on Sep 27, 2004 at 14:23 UTC
    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.


        Hi
        Thanks for the tip. I was able to figure that out the hard way by carefully seeing where by browser was going. I didnt know about the META tag. I am now able to download the file 'https://secure2.playboy.com/security/cookieGenerator.do'
        Once again this file is a redirect to
        https://secure2.spicetv.com/security/cookieGenerator.do
        but with a lot of cookie information added at the end. So I am trying to get the value of the "content" attribute of the "meta" tag.
        I am now trying to parse the html file using HTML::TokeParserL::Simple. The trouble is the html file has the first few lines as the new line character and each line after that has a new line character. The HTML::TokerParser::Simple is choking on the malformed (??) html. So I am trying to remove the lines which have only a new line character (^M) and remove the ^M at the end of each line. Since this is my first time with perl I am struggling with this simple task.
        Any help or code sample to strip off lines with only a new line character and the new line character at the end of each line is appreciated. I am trying to use chomp but dont know how to loop through the entire output of mech->content
        If I clean up the html file by hand and then run the following script
        my $p = HTML::TokeParser::Simple->new( $html ); my $token = $p->get_token; my $tag = "meta"; my $att = "content"; if ( $token->is_tag($tag) ) { print "There is a $tag tag\n" }; my $att_value = $token->get_attr($att); print "The value of the $att attribute of the $tag tag is $att_value \ +n\n\n\n"; my $url = substr($att_value,6); print $url,"\n";

        Iam able to get the info I need but cleaning up the html file is the problem
        Thanks