#!/usr/bin/perl -w
use WWW::Mechanize
$adres = qq{http://debian.ds/};
$mech = WWW::Mechanize->new();
$mech->get( $adres );
$mech->click( 'agreed' );
print $mech->content;
#
我得到: 没有在/usr/local/share/perl/5.14.2/WWW/Mechanize.pm第1707行同意的可点击输入。
Html看起来像这样:
<fieldset class="submit-buttons">
<input type="submit" name="agreed" id="agreed" value="text1" class="button1" />
<input type="submit" name="not_agreed" value="text2" class="button2" />
<input type="hidden" name="change_lang" value="" />
<input type="hidden" name="creation_time" value="1373067606" />
<input type="hidden" name="form_token" value="83ab2ec47bc4ee37f" />
</fieldset>
答案 0 :(得分:2)
我认为你需要先选择你想要使用的表格。
来自CPW on WWW :: Mechanize
$mech->forms
Lists all the forms on the current page. Each form is an HTML::Form object. In list context, returns a list of all forms. In scalar context, returns an array reference of all forms.
$mech->form_number($number)
Selects the numberth form on the page as the target for subsequent calls to "field()" and "click()". Also returns the form that was selected.
If it is found, the form is returned as an HTML::Form object and set internally for later use with Mech's form methods such as "field()" and "click()".
Emits a warning and returns undef if no form is found.
The first form is number 1, not zero.
答案 1 :(得分:0)
my $mech = WWW::Mechanize->new;
$mech->get('file:///tmp/so17498270.html');
$mech->submit_form(
with_fields => {
agreed => 'text1',
}
);