我当前的程序可以在包含字段名称的网页中打印所有表单,我也想打印当前值。
use WWW::Mechanize;
use LWP::UserAgent;
my $m = WWW::Mechanize->new();
$m->get("http://www.rediff.com/");
@arr = $m->forms;
$count = 1;
foreach (@arr) {
my @inputfields = $_->param;
print "form $count fields are:\n";
$count++;
foreach (@inputfields) {
print "$_\n";
}
print "\n";
}
输出:
form 1 fields are:
srchword
src
form 2 fields are:
login
passwd
remember
seclogin
FormName
预期: 我想显示值,比如
login : abc@rediff.com
答案 0 :(得分:1)
使用HTML::Form
中记录的$form->value
方法:
use strict;
use warnings;
use WWW::Mechanize;
my $m = WWW::Mechanize->new();
$m->get("http://www.rediff.com/");
my $count = 1;
for my $form ($m->forms) {
print "form $count fields are:\n";
$count++;
for ($form->param) {
printf "%s - %s\n", $_, $form->value($_);
}
print "\n";
}
输出:
form 1 fields are:
srchword -
src - web
form 2 fields are:
login -
passwd -
remember - 1
seclogin - on
FormName - existing