根据ID选择表单
出于测试目的,我尝试使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您已通过 id 属性选择了表单,但这不允许您使用 id 属性来选择字段,这应该修复您的代码:
如果出现错误,请将字段名称括在单引号中,不确定正方形是否括号会成为问题。
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:
If you get an error, enclose the field names in single quotes, not sure whether the square brackets will be a problem.
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();