gpt4 book ai didi

perl - WWW::Mechanize 文本字段问题

转载 作者:行者123 更新时间:2023-12-02 04:03:55 25 4
gpt4 key购买 nike

我正在尝试使用 WWW::Mechanize 通过 post 方法提交表单perl 模块。

use WWW::Mechanize;

my $mech = WWW::Mechanize->new();
...
$mech->get($url);
...
my $response = $mech->submit_form(
form_name => $name,
fields => {
$field_name => $field_value
},
button => 'Button'
);
$field_name一般来说是一个文本字段(虽然在表单中没有明确指定类型),它有一个预设值。
$field_name => $field_value$mech->submit_form无论出于何种原因都不会替换该值,而是 $field_value在原始值之后添加到表单中:
{submitted_field_value} = {original_value},{provided_value}

如何更换 {original_value}{provided_value}在要提交的表格中?

最佳答案

如果在调用 $mech->submit_form() 之前将这一行添加到代码中会发生什么:

$mech->field( $name, [$field_value], 1 );

这确保了第一个值被添加,或者如果它已经存在则被覆盖。
1 是数字参数(或位置索引)

参见 WWW::Mechanize 的文档:

$mech->field( $name, \@values, $number )

Given the name of a field, set its value to the value specified. [...]

The optional $number parameter is used to distinguish between two fields with the same name. The fields are numbered from 1.

关于perl - WWW::Mechanize 文本字段问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8686237/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com