【发布时间】:2017-01-04 05:53:05
【问题描述】:
当我在 phantomjs_arg 中使用“--disk-cache=true”时,在这一行中出现错误:
my $form = $self->{obj_mech}->form_number( 2 );
在 modules/TestLogin.pm 第 1129 行未找到表单编号 2 的元素。 在 /usr/local/share/perl/5.22.1/WWW/Mechanize/PhantomJS.pm 第 796 行。 WWW::Mechanize::PhantomJS::signal_condition(WWW::Mechanize::PhantomJS=HASH(0x4cfa120), “未找到表格编号 2 的元素”)调用于 /usr/local/share/perl/5.22.1/WWW/Mechanize/PhantomJS.pm 第 1732 行 WWW::Mechanize::PhantomJS::xpath(WWW::Mechanize::PhantomJS=HASH(0x4cfa120), "(//form)[2]", "user_info", "form number 2", "single", 1) 调用于 /usr/local/share/perl/5.22.1/WWW/Mechanize/PhantomJS.pm 第 2102 行 WWW::Mechanize::PhantomJS::form_number(WWW::Mechanize::PhantomJS=HASH(0x4cfa120), 2) 在 modules/TestLogin.pm 第 1129 行调用 在 collectBets.pl 第 20 行调用的 TestLogin::TestLogin_login(TestLogin=HASH(0x4f5c8a8)) 已调试程序终止。使用 q 退出 或 R 重新启动,使用 o inhibitor_exit 避免程序后停止 终止、h q、h R 或 h o 以获取更多信息。
没有磁盘现金它工作正常。 这是我的示例代码,以便更好地理解。
#!/usr/bin/perl
use strict;
use warnings;
use Helper;
use WWW::Mechanize::PhantomJS;
use DataBase;
use MyConfig;
use JSON;
use DateTime;
use HTML::Entities;
sub new($$) {
my ($class,$params) = @_;
my $self = $params || {};
bless $self, $class;
$self->{obj_mech} = WWW::Mechanize::PhantomJS -> new( phantomjs_arg => ['--ssl-protocol=any','--disk-cache=true','--max-disk-cache-size=1024'], ignore_ssl_errors => 1);
$self->{obj_helper} = new Helper();
#$self->{obj_db} = new DataBase();
$self->{logged_in} = 0;
#$self->setTorProxy();
#$self->init_market_master();
return $self;
}
Login();
print "\nlogin done...\n";
exit;
sub Login {
my ($self) = @_;
my $html = $self->{obj_mech}->get( "https://www.gmail.com/" );
sleep(25);
$html = $self->{obj_mech}->content;
$self->{obj_mech}->viewport_size({ width => 1366, height => 768 });
my $form = $self->{obj_mech}->form_number( 2 );
my $user_name = '*****';
my $password = '******';
$self->{obj_mech}->set_fields('InputEmail' =>$user_name);
$self->{obj_mech}->set_fields('InputPassword' =>$password);
$self->{obj_mech}->click({ xpath => '//button[@class="PrimaryButton"]' });
sleep(20);
my $test_html=$self->{obj_mech}->content;
$self->{obj_helper}->writeFileNew( "TestLoginPage.html" , $test_html );
my $png = $self->{obj_mech}->content_as_png();
$self->{obj_helper}->writeFileNew( "LoginPage.png" , $png );
return 1;
}
【问题讨论】: