0
#!/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" />&nbsp;
<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>
4

2 回答 2

2

我认为您需要先选择要使用的表格。

来自 WWW::Mechanize 上的 CPAN

$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.
于 2013-07-06T00:21:34.387 回答
0
my $mech = WWW::Mechanize->new;
$mech->get('file:///tmp/so17498270.html');
$mech->submit_form(
    with_fields => {
        agreed => 'text1',
    }
);
于 2013-07-07T12:42:36.753 回答