1

我应该如何检查这样的复选框:

<td><center><INPUT name="test2%40mydomain.com_notmetoo" type="CHECKBOX" value="off" ></center></td>

使用 Perl 的 LWP::UserAgent 模块?

此代码执行此操作(输出就好像它是在未选中复选框的情况下提交的 - 即网页被刷新并且复选框被清除)。

#!/usr/bin/perl
use LWP::UserAgent;

$ua = new LWP::UserAgent;
$ua->cookie_jar({ file => "$ENV{HOME}/.mailmanrc" });

$res = $ua->post('http://mydomain.com/mailman/admin/test1_mydomain.com/members/list',
    Content_Type => 'form-data',
    Content => [
        'test2%40mydomain.com_notmetoo' => 'on',
        setmemberopts_btn => 'Submit Your Changes'
    ]
);
if ($res->is_success) {
    print $res->decoded_content;
    print "Changed user setting...I hope!\n";
}
else {
    die $res->status_line;
}

我不确定为什么元素名称中的“@”由“%40”表示(有什么想法吗?),但我也尝试过: 'test2\%40mydomain.com_notmetoo' => 'on',' test2@mydomain.com_notmetoo' => 'on', 没有成功。

网站上似乎没有 JavaScript(即它在禁用 JavaScript 的浏览器中运行良好)。我只是无法让它在 Perl 中工作。

谢谢。

特里。


更新 #1:这是我在检查 Test2 的 notmetoo 框后提交时来自 Firefox 的“篡改数据”扩展的 POSTDATA 值:

POSTDATA =-----------------------------2921376274802
Content-Disposition: form-data; name="findmember"


-----------------------------2921376274802
Content-Disposition: form-data; name="test1%40mydomain.com_realname"

Test1
-----------------------------2921376274802
Content-Disposition: form-data; name="user"

test1%40mydomain.com
-----------------------------2921376274802
Content-Disposition: form-data; name="test1%40mydomain.com_hide"

on
-----------------------------2921376274802
Content-Disposition: form-data; name="test1%40mydomain.com_notmetoo"

on
-----------------------------2921376274802
Content-Disposition: form-data; name="test1%40mydomain.com_plain"

on
-----------------------------2921376274802
Content-Disposition: form-data; name="test1%40mydomain.com_language"

en
-----------------------------2921376274802
Content-Disposition: form-data; name="test2%40mydomain.com_realname"

Test2
-----------------------------2921376274802
Content-Disposition: form-data; name="user"

test2%40mydomain.com
-----------------------------2921376274802
Content-Disposition: form-data; name="test2%40mydomain.com_hide"

on
-----------------------------2921376274802
Content-Disposition: form-data; name="test2%40mydomain.com_notmetoo"

off
-----------------------------2921376274802
Content-Disposition: form-data; name="test2%40mydomain.com_plain"

on
-----------------------------2921376274802
Content-Disposition: form-data; name="test2%40mydomain.com_language"

en
-----------------------------2921376274802
Content-Disposition: form-data; name="test3%40mydomain.com_realname"

Test3
-----------------------------2921376274802
Content-Disposition: form-data; name="user"

test3%40mydomain.com
-----------------------------2921376274802
Content-Disposition: form-data; name="test3%40mydomain.com_hide"

on
-----------------------------2921376274802
Content-Disposition: form-data; name="test3%40mydomain.com_plain"

on
-----------------------------2921376274802
Content-Disposition: form-data; name="test3%40mydomain.com_language"

en
-----------------------------2921376274802
Content-Disposition: form-data; name="setmemberopts_btn"

Submit Your Changes
-----------------------------2921376274802
Content-Disposition: form-data; name="allmodbit_val"

0
-----------------------------2921376274802--

这对任何人帮助我有帮助吗?

4

2 回答 2

2

My understanding of checkboxes is that the value= specifies the value which the variable will have when the checkbox is checked. So your confusing value="off" actually means thay you need

'test2%40mydomain.com_notmetoo' => 'off'

To indicate that the box is checked.

于 2012-08-15T01:58:31.970 回答
1

在您的情况下,复选框在选中时将具有“关闭”值。如果 value 类似于value="checkbox1". 在这种情况下,复选框的值将被checkbox1选中。

此外,考虑使用WWW::Mechanize像这样的基本 Web 操作(没有 javascript),它更容易和直观,也是WWW::Mechanize一个子类,LWP::UserAgent所以你仍然可以使用 LWP 的方法。

于 2012-08-15T04:31:56.463 回答