Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Filling out form in Perl with the WWW::Mechanize module

I am creating a script that logs into a web form in Perl using the mechanize module, and I'm getting the error:

syntax error at /home/arty/scripts/gmail_pw_chngr.pl line 18, near "button" Execution of /home/arty/scripts/gmail_pw_chngr.pl aborted due to compilation errors.

Code

    use WWW::Mechanize;
    my $mech = WWW::Mechanize->new();

    my $url = "https://accounts.google.com/Login";

    $mech->get($url);

    $result = $mech->submit_form(
        form_name => 'gaia_loginform', # Name of the form
        #Instead of form name you can specify
        #form_number => 1
        fields       =>
        {
            Email  => '[email protected]', # Name of the input field and value
            Passwd => 'password',
        }
        button    => 'signIn' # Name of the submit button
    );
    print $result->content();

Above is the code, all the values from the input are the name, but it always errors on the same line.

like image 283
user1664433 Avatar asked Dec 26 '22 13:12

user1664433


2 Answers

The error in question is the missing comma before button.

like image 160
ikegami Avatar answered Jan 28 '23 13:01

ikegami


Use use strict; and use warnings;. They would help you.

like image 45
varnie Avatar answered Jan 28 '23 13:01

varnie