gpt4 book ai didi

Python Mechanize 检查是否需要字段

转载 作者:行者123 更新时间:2023-12-04 16:20:13 24 4
gpt4 key购买 nike

我正在尝试 Mechanize 图书馆来注册用户。有 4 个字段名字,姓氏,电子邮件,密码。每个字段都是必需的,但是如果我运行此代码,它会成功运行并且不会出错,也不会注册用户(缺少姓氏)。如何在提交表单之前检查所有必填字段?

import csv
import mechanize

br = mechanize.Browser()
#br.set_all_readonly(False) # allow everything to be written to
br.set_handle_robots(False) # ignore robots
br.set_handle_refresh(False) # can sometimes hang without this
br.addheaders = [('User-agent', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.122 Safari/537.36')] # [('User-agent', 'Firefox')]

response = br.open('abc.com/register.aspx')

for form in br.forms():
print ("Form name:", form.name)

br.select_form("TheForm")

br.form['txtEmail$TheBox'] = 'abc@xyz.com';
br.form['txtPass$TheBox'] = 'abcxyz123';
br.form['txtFname$TheBox'] = 'abc';

response = br.submit()
print(response.read())

最佳答案

后:

br.select_form("TheForm")

用:
for control in br.controls: print control

这应该显示所有必填字段。

关于Python Mechanize 检查是否需要字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61062090/

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