--------------------------------------------------------------------
#!/usr/bin/perl
use strict;
use WWW::Mechanize;
use HTTP::Cookies;
my $outfile = "out.htm";
#my $url = 'http://www7.i.demo.com/cgi-bin/login';
my $username = 'hello@demo.com';
my $password = "test";
my $mech = WWW::Mechanize->new(autocheck => 1);
$mech->cookie_jar(HTTP::Cookies->new());
$mech->post(
'http://www7.i.demo.com/cgi-bin/login',
[
'User-Agent' => 'Mozilla/5.0 (Windows; U; Windows NT
5.1; zh-CN; rv:1.9.0.11) Gecko/2009060215 Firefox/3.0.11',
'LoginName' => "$username",
'Password' => "$password",
],
);
my $output_page = $mech->content();
open(OUTFILE, ">$outfile");
print OUTFILE "$output_page";
close(OUTFILE);
------------------------------------------------------
但是模仿提交form 有问题, 代码如下:
-----------------------------------------------------
#!/usr/bin/perl
use strict;
use WWW::Mechanize;
use HTTP::Cookies;
my $outfile = "out.htm";
my $url = 'http://www7.i.demo.com/cgi-bin/login';
my $username = 'hello@demo.com';
my $password = "test";
my $mech = WWW::Mechanize->new(autocheck => 1);
$mech->cookie_jar(HTTP::Cookies->new());
$mech->post($url); #$mech->get($url);这个应该是post吧?
$mech->form_name('Logon');
$mech->field(LoginName => $username);
$mech->field(Password => $password);
$mech->submit();
my $output_page = $mech->content();
open(OUTFILE, ">$outfile");
print OUTFILE "$output_page";
close(OUTFILE);
-------------------------------------------------------
报错:
There is no form named "Logon" at C:\DOCUME~1\wf\LOCALS~1\Temp
\dirDB0.tmp\02.pl line 12
Can't call method "value" on an undefined value at C:/Perl/site/lib/
WWW/Mechanize.pm line 1348.
网页部分源码:
<div id="logonForm">
<form method="post" action="/cgi-bin/login" id="Logon" name="Logon"
onsubmit="return val.isValid()">
问题:根据源码来看 $mech->form_name('Logon'); 应该没错吧?
可是为什么error显示无此form呢?
跟js有关么?
多谢
--~--~---------~--~----~------------~-------~--~----~
您收到此信息是由于您订阅了 Google 论坛"PerlChina Mongers 讨论组"论坛。
要在此论坛发帖,请发电子邮件到 perlchina@googlegroups.com
要退订此论坛,请发邮件至 perlchina+unsubscribe@googlegroups.com
更多选项,请通过 http://groups.google.com/group/perlchina?hl=zh-CN 访问该论坛
-~----------~----~----~----~------~----~------~--~---
没有评论:
发表评论