Question

I have some problems with login in asp page.

Here is my code:

#!/usr/bin/perl -w
use strict;
use warnings;
use WWW::Mechanize;
use LWP::Debug qw(+);
my $mech = WWW::Mechanize->new;
$mech->agent('User-Agent=Mozilla/4.0');
$mech->get( 'http://site.net/index.asp' );
$mech->submit_form(
    form_name => 'form',
    fields      => {
        xpto    => '123'
    }
);
my $app_content = $mech->content();
print "$app_content\n";

And that's what i get from terminal:

    <html>
    <head>
        <title>Anti Bot</title>
    </head>
    <body>
        <h1 style="color:red;">Bots are not allowed here</h1>
    </body>
</html>
Was it helpful?

Solution

Either it's detecting that your user agent is weird (most do not start with "User-Agent="), or there's javascript in the form which is setting (or removing) fields during a normal submission via a browser. Try filling out the login form in a browser and observing what is actually posted (via Firebug, etc), and updating your script to match. Alternatively, use a web scraping library which can run javascript, such as WWW::Mechanize::Firefox.

I am assuming, of course, that you have permission to be doing this. Some people have good reasons for not wanting bots on their site.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top