根据ID选择表单

发布于 2024-10-08 13:05:13 字数 433 浏览 0 评论 0原文

出于测试目的,我尝试使用 WWW::Mechanize 编写一个脚本,该脚本将通过 https://api 登录 Gowalla。 gowalla.com/signin

正如我所看到的,登录表单没有“name”属性,但有一个“id”属性。 Mech 有一个“submit_form”方法,可以获取名称作为参数,但我没有看到它接受 id 作为参数。

那么会是这样吗

$w->form_id('form_signin');
$w->submit_form(
fields => {
    username => $username,
    user_session_password => $password,
});

For testing purposes I am trying to write a script using WWW::Mechanize that would login to Gowalla via https://api.gowalla.com/signin

As I can see the login form does not have a "name" attribute but it has an "id" attribute.
Mech has a "submit_form" method that can get the name as a parameter but I don't see it accepting the id as a parameter.

So would that be then

$w->form_id('form_signin');
$w->submit_form(
fields => {
    username => $username,
    user_session_password => $password,
});

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

摘星┃星的人 2024-10-15 13:05:13

您已通过 id 属性选择了表单,但这不允许您使用 id 属性来选择字段,这应该修复您的代码:

$w->submit_form(
fields => {
    user_session[username] => $username,
    user_session[username] => $password,
});

如果出现错误,请将字段名称括在单引号中,不确定正方形是否括号会成为问题。

You've selected the form via id attribute, but that doesn't allow you to use id attribute to select fields, this should fix your code:

$w->submit_form(
fields => {
    user_session[username] => $username,
    user_session[username] => $password,
});

If you get an error, enclose the field names in single quotes, not sure whether the square brackets will be a problem.

你与昨日 2024-10-15 13:05:13

WWW::Mechanize 自动将焦点设置到单个表单上。您可以使用 $m->click('') 或 $m->submit(); 提交。

WWW::Mechanize sets the focus onto the single form automatically. You can submit it with $m->click('') or $m->submit();

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文