in reply to Re^2: problem login using WWW::Mechanize
in thread problem login using WWW::Mechanize

Thats what a cookie_jar is for
  • Comment on Re^3: problem login using WWW::Mechanize

Replies are listed 'Best First'.
Re^4: problem login using WWW::Mechanize
by shekarkcb (Beadle) on Jun 10, 2008 at 12:25 UTC
    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
Re^4: problem login using WWW::Mechanize
by Anonymous Monk on Jun 10, 2008 at 16:26 UTC
    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