使用 Mechanize 提交 Web 自动化表单 - 返回错误
for control in form.controls:
if control.type == 'text':
if 'user' in control.name:
control.value = 'blah'
if 'mail' in control.name:
control.value = 'blah'
if control.type == 'password':
if 'pass' in control.name:
control.value = 'blah'
if control.type == 'checkbox':
if 'agree' in control.name:
control.selected = True
if control.type == 'submit':
if 'Submit' in control.name:
control.readonly = False
我就是这样填写表格的。然后我选择“同意”复选框,之后我尝试使用 br.submit() 提交表单并发送数据。我得到的错误:
AttributeError: SubmitControl 实例没有属性“click”
这是提交和同意控件的 HTML 源代码:
<input type="submit" name="regSubmit" value="Register" />
<label for="regagree"><input type="checkbox" name="regagree" onclick="checkAgree();" id="regagree" class="check" /> <b>I Agree</b></label>
该特定网站的 HTML 源代码有这样的 JavaScript:
function verifyAgree()
{
if (document.forms.creator.passwrd1.value != document.forms.creator.passwrd2.value)
{
alert("The two passwords you entered are not the same!");
return false;
}
if (!document.forms.creator.regagree.checked)
{
alert("Please read and accept the agreement before registering.");
return false;
}
return true;
}
function checkAgree()
{
document.forms.creator.regSubmit.disabled = isEmptyText(document.forms.creator.user) || isEmptyText(document.forms.creator.email) || isEmptyText(document.forms.creator.passwrd1) || !document.forms.creator.regagree.checked;
setTimeout("checkAgree();", 1000);
}
setTimeout("checkAgree();", 1000);
当我在 IDLE 中键入打印表单时,表单为返回为已填充,并且选择了所有正确的控件。我一生都无法弄清楚为什么这不起作用。我已经搞了两天了
非常感谢您的帮助。
for control in form.controls:
if control.type == 'text':
if 'user' in control.name:
control.value = 'blah'
if 'mail' in control.name:
control.value = 'blah'
if control.type == 'password':
if 'pass' in control.name:
control.value = 'blah'
if control.type == 'checkbox':
if 'agree' in control.name:
control.selected = True
if control.type == 'submit':
if 'Submit' in control.name:
control.readonly = False
I fill the form out this way. Then I go to selected the "Agree" checkbox, after doing that I try to use br.submit() to submit the form and send the data. The error I get it:
AttributeError: SubmitControl instance has no attribute 'click'
This is the HTML source of the submit and agree controls:
<input type="submit" name="regSubmit" value="Register" />
<label for="regagree"><input type="checkbox" name="regagree" onclick="checkAgree();" id="regagree" class="check" /> <b>I Agree</b></label>
The HTML source of this particular website has this JavaScript:
function verifyAgree()
{
if (document.forms.creator.passwrd1.value != document.forms.creator.passwrd2.value)
{
alert("The two passwords you entered are not the same!");
return false;
}
if (!document.forms.creator.regagree.checked)
{
alert("Please read and accept the agreement before registering.");
return false;
}
return true;
}
function checkAgree()
{
document.forms.creator.regSubmit.disabled = isEmptyText(document.forms.creator.user) || isEmptyText(document.forms.creator.email) || isEmptyText(document.forms.creator.passwrd1) || !document.forms.creator.regagree.checked;
setTimeout("checkAgree();", 1000);
}
setTimeout("checkAgree();", 1000);
When I type print forms into IDLE, the form is returned as filled and all the proper controls are selected. I can't for the life of me figure out WHY this isn't working. I've been at it for two days.
Help is greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为什么不直接提交文档示例中所示的表单
:只有一种提交表格的方式;使用 JavaScript 是另一回事。因此您无需费力寻找提交控件。
Why not just submit the form as it is shown in the documentation sample:
Clicking on the submit button is just one way to submit the form; using JavaScript is another. So you don't need to go through the trouble of finding the submit control.