in reply to problem login using WWW::Mechanize

First of all, you go to Firefox's Tools -> Page Info menu item and click on the "Forms" tab to see what forms are present in the page. In this case it looks like the second form is the login form. It doesn't have a name so you have to identify it by number.

Then use the submit_form example from the WWW::Mechanize documentation (which your first attempt seems to be based on):

use strict; use warnings; use WWW::Mechanize; my $m = WWW::Mechanize->new( autocheck => 1 ); $m->get("https://www.bittorrent.com/account/signin"); $m->submit_form( form_number => 2, fields => { username => 'mungo', password => 'lost-and-alone', } ); print $m->content;
This seems to work as it returns a page with the text: "The username and password you entered does not match a registered user."

Replies are listed 'Best First'.
Re^2: problem login using WWW::Mechanize
by shekarkcb (Beadle) on Jun 10, 2008 at 06:29 UTC
    Really thanx... lot
    

    But dude can you tell me , how can i remember cookies? this is very important because, i want to extract meta data's ( title, Genre, ...and torrent url .torrent) for a particular movie and this has to be in loop . I have the code to do so, Now the question is it asks (bittorrent) user name and password every time i entered rented page, If you are using a browser then once you login then browser remembers the cookies and you need not to login again and again... and you can enter any page and access any content. I just want the same task to be automated. I have the code that does all automation but i have stuckked in Login and remembering cookies please can you siggest me.... you can also mail me @ shekarkcb@gmail.com Thanx, Shekar

      Thats what a cookie_jar is for
        Thanx Again...

        So you mean to say that the below code examples the same right?


        
        use HTTP::Cookies;
        use WWW::Mechanize;
        
        my $cookiefile = 'cookies.txt';
        my $cookie_jar = HTTP::Cookies->new(File => $cookiefile, autosave =>1);
        my $m = WWW::Mechanize->new( autocheck => 1 );
        $m->cookie_jar($cookie_jar);
        my $url="https://www.bittorrent.com/account/signin";
        $m->get($url);
        $m->submit_form(
              form_number => 2,
              fields      => {
                 username    => 'abcd',
                 password    => 'abcd',
              }
        );
        
        
        my $content= $m->content;
        
        

        and from now you can use $m to do any thing i mean to say can i use $m to get content of any linked page inside the login page ??? something like this??

        if($content =~ m/<li id=\"movies\"><a href=\"(.*?)\" title=\"Movies\"> +Movies<\/a><\/li>/i) { my $movie = $1; $m->get($movie); my $content_1 = $m->content; if($content_1 =~ m/<h3><a href=\"(.*?)\" title=\"\">Browse All +<\/a><\/h3>/i) { my $movie_1 = $1; $movie_1 \n"; $m->get($movie_1)||die ("\nCan't Get the Browse URL\n" +); my $content_2 = $m->content; if($content_2 =~ m/<li><a href=\"(.*?)\">Rent<\/a><\/l +i>/i) { my $movie_2 = $1; $movie_2=~ s/&amp;/&/g; $m->get($movie_2)||die("\nCant Get The Rent UR +L\n"); $content_3 = $m->content; } } else { print "Not Matched Rent URL\n"; } } else { print "\nSorry Not Matched Browse All\n"; }} else { print "\nNot matched Movie page\n"; }

        So If any thing requires in $content_3 page requires a authentication then will my code 2ndpartremembers the earlier cookies as i have coded above see Ist part Please suggest me ....



        Thanx, Shekar
        Thanx Again...

        So you mean to say that the below code examples the same right?


        
        use HTTP::Cookies;
        use WWW::Mechanize;
        
        my $cookiefile = 'cookies.txt';
        my $cookie_jar = HTTP::Cookies->new(File => $cookiefile, autosave =>1);
        my $m = WWW::Mechanize->new( autocheck => 1 );
        $m->cookie_jar($cookie_jar);
        my $url="https://www.bittorrent.com/account/signin";
        $m->get($url);
        $m->submit_form(
              form_number => 2,
              fields      => {
                 username    => 'abcd',
                 password    => 'abcd',
              }
        );
        
        
        my $content= $m->content;
        
        

        and from now you can use $m to do any thing i mean to say can i use $m to get content of any linked page inside the login page ??? something like this??

        if($content =~ m/<li id=\"movies\"><a href=\"(.*?)\" title=\"Movies\"> +Movies<\/a><\/li>/i) { my $movie = $1; $m->get($movie); my $content_1 = $m->content; if($content_1 =~ m/<h3><a href=\"(.*?)\" title=\"\">Browse All +<\/a><\/h3>/i) { my $movie_1 = $1; $movie_1 \n"; $m->get($movie_1)||die ("\nCan't Get the Browse URL\n" +); my $content_2 = $m->content; if($content_2 =~ m/<li><a href=\"(.*?)\">Rent<\/a><\/l +i>/i) { my $movie_2 = $1; $movie_2=~ s/&amp;/&/g; $m->get($movie_2)||die("\nCant Get The Rent UR +L\n"); $content_3 = $m->content; } } else { print "Not Matched Rent URL\n"; } } else { print "\nSorry Not Matched Browse All\n"; }} else { print "\nNot matched Movie page\n"; }

        So If any thing requires in $content_3 page requires a authentication then will my code 2ndpartremembers the earlier cookies as i have coded above see Ist part Please suggest me ....



        Thanx, Shekar