views:

70

answers:

2

I want to post my user and password with Perl to a website. The source of the login page is:

<div class="top">Sign In</div>
    <div class="row"><label for="username">Username:</label></div>
    <div class="row"><div id="login:usernameContainer">
        <input id="login:usernameContainer:username" type="text"
        name="login:usernameContainer:username" class="username" size="16" />
    </div></div>
    <div class="row"><label for="password">Password:</label></div>
    <div class="row"><div id="login:j_id598">
        <input id="login:j_id598:password" type="password"
        name="login:j_id598:password" value="" size="16" class="password" />
    </div></div>
    <div class="clearfix">
    <div class="row rememberme">
        <input id="login:rememberme" type="checkbox"
        name="login:rememberme" class="rememberme" />Remember Me
    </div>
    <div class="submit-button">
        <input type="image" src="/beta/style/shun/base/base/en/text/button/button-login.gif"
        name="login:j_id603" />
    </div>
</div>

What am I going to do to post my user and password?

Thanks in advance.

+1  A: 

You use appropriate field names (you can find them in the HTML you posted) and populate the form values for whatever Perl code you use to post to the page (WWW::Mechanize or whatever else you use)

DVK
my problem is in this line : <div class="submit-button"><input type="image" src="/beta/style/shun/base/base/en/text/button/button-login.gif" name="login:j_id603" />and i can't send submit with perl . can you help me ?
Eve
you need to use WWW::Mechanize
xenoterracide
+1  A: 

See http://search.cpan.org/dist/WWW-Mechanize/lib/WWW/Mechanize.pm for details on the module, but here's a stab at it:

use strict; use warnings;
use WWW::Mechanize;
my $mech = WWW::Mechanize->new();
$mech->get( 'http://url.to/your/form' );
$mech->submit_form(
    form_number => 0,     # see if it's the first form, or change this
    fields      => {
        'login:usernameContainer:username'
            => 'username', # change to your user name
        'login:j_id598:password'
            => 'password', # change to your password
    }
);

If it doesn't work for you, or the fields have always different names or such, try using $mech->find_link with a regex and use the returned values to change the fields you need, then submit the form.

hope this helps

mfontani