4

我正在创建一个脚本,该脚本使用 mechanize 模块在 Perl 中登录 Web 表单,但出现错误:

/home/arty/scripts/gmail_pw_chngr.pl 第 18 行,“按钮”附近的语法错误 /home/arty/scripts/gmail_pw_chngr.pl 的执行由于编译错误而中止。

代码

    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  => 'arty32l@gmail.com', # Name of the input field and value
            Passwd => 'password',
        }
        button    => 'signIn' # Name of the submit button
    );
    print $result->content();

上面是代码,输入中的所有值都是名称,但它总是在同一行出错。

4

3 回答 3

7

有问题的错误是缺少逗号 before button

于 2012-12-09T05:27:04.840 回答
3

使用use strict;use warnings;。他们会帮助你。

于 2012-12-09T13:39:44.373 回答
0
use CGI qw(:standard);
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);

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    => 'arty32l@gmail.com', # name of the input field and value
     Passwd    => 'password',
    }
    ,button    => 'signIn' #name of the submit button
    );

     print $result->content();
于 2012-12-09T14:10:00.017 回答