Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Insert into crawl_update
- # This will enable login to a Mindtouch Wiki, and possibly other sites with form-based authentication and http redirect instead of 401 codes.
- # See login form here: http://pastebin.com/cnRv96hv
- use LWP::UserAgent;
- use HTML::Form;
- use HTTP::Cookies;
- my $userAgent = LWP::UserAgent->new;
- $userAgent->timeout(30);
- my $loginUrl = "http://<<sitename>>/index.php?title=Special:Userlogin&returntotitle="; # change
- # Form-auth
- my @inputs;
- my $inp;
- my $type;
- my $name;
- my @form_out;
- my $form;
- my $cookie = HTTP::Cookies->new;
- my $response = $userAgent->get($loginUrl);
- my @forms = HTML::Form->parse($response);
- undef(@form_out);
- $form = shift(@forms); #Not the right form
- $form = shift(@forms);
- @inputs = $form->inputs;
- for (my $i=0 ; $i<=$#inputs ; $i++) {
- $inp = $inputs[$i];
- $type = $inp->type;
- $name = $inp->name;
- if ($inp->name eq "username") {
- push(@form_out,$name,$user);
- }
- elsif ($inp->name eq "auth_id") {
- push(@form_out,$name,"16");
- }
- elsif ($inp->name eq "returntotitle") {
- push(@form_out,$name,"");
- }
- elsif ($inp->name eq "returntourl") {
- push(@form_out,$name,"");
- }
- elsif ($inp->name eq "password") {
- push(@form_out,$name,$passw);
- }
- }
- $response = $userAgent->post("http://wiki.hemit.helsemn.no/Special:UserLogin", \@form_out);
- $cookie->extract_cookies($response);
- # After initializing the robot, insert:
- $robot->cookie_jar($cookie);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement