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

Hi all,

I have tried to automate bittorrent site (browsing). So there it requires username and password. and then click button sign in. but i didn't find any ways login (enter next field) so. below are the ways i have tried ,please assist me if any mistakes.....

1st Method:-
use WWW::Mechanize; my $m = WWW::Mechanize->new( autocheck => 1 ); $m->get("https://www.bittorrent.com/account/signin"); $mech->submit_form( form_name => 3, #I don't know what is this simply i gave fields => { username => "abcd", password => "abcd", }, button => 'Sign In', );
2nd Method:-
use WWW::Mechanize; use HTTP::Cookies; my $outfile = "Result.htm"; my $url = "https://www.bittorrent.com/account/signin"; my $username = "abcd"; my $password = "abcd"; my $cookiefile = 'cookies.txt'; my $cookie_jar = HTTP::Cookies->new(File => $cookiefile, autosave =>1) +; my $mech = WWW::Mechanize->new(); $mech->cookie_jar($cookie_jar); $mech->get($url); print "form submit failed!", $mech->response->status_line, "\n" unless + $mech->success; $mech->set_visible( $username ); $mech->click_button(value => "Sign In");
3rd Method:-
use WWW::Mechanize; use URI::URL; use LWP::Simple; $url="https://www.bittorrent.com/account/signin"; $m=WWW::Mechanize->new(); $m->get($url); $content=$m->content; open(FD,">>html"); print FD "$content\n"; $username="shekar"; $password="shekar"; $m->set_visible($username,$password); $m->submit();

Please Sugest me to overcome this problem.... you can mail me @ shekarkcb@gmail.com

regards shekar

Replies are listed 'Best First'.
Re: problem login using WWW::Mechanize
by pc88mxer (Vicar) on Jun 09, 2008 at 14:55 UTC
    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."
      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