0
我在蟒蛇新节目,最近尝试登录私人网站与机械化;我读到这样类似的问题: How to bypass Mechanize "AmbiguityError" in Python,python mechanize handle two parameters with same name,但是这些非可以帮助和有没有反馈解决方案的第二个链接。据我所知,使用br.select_form(nr = 0)应该足以选择第一种形式,但我仍然卡住;我试着用AttributeError改变br.select_form(form的名字)和br.form.find_control():'NoneType'对象没有属性'find_control';所有选项都没有成功。 下面的代码和表单的列表可以找到。支持表示赞赏。由于ClientForm.AmbiguityError:不止一个控制匹配名称
这是所使用的代码:
br = mechanize.Browser()
br.set_handle_robots(False)
cj = cookielib.LWPCookieJar()
br.set_cookiejar(cj)
br.select_form(nr=0)
br.form["username"]= 'Myusername'
br.form["password"]= 'Mypassword'
br.submit()
这些都是形式:
<HiddenControl(smauthreason=0) (readonly)>
<HiddenControl(clientfp=) (readonly)>
<HiddenControl(smtryno=0) (readonly)>
<TextControl(username=)>
<PasswordControl(password=)>
<TextControl(username=)>
<PasswordControl(password=)>
<TextControl(username=)>
<PasswordControl(password=)>
<IgnoreControl(submitFrm=<None>)>
<HiddenControl(SMAGENTNAME= "deleted by me") (readonly)>
<HiddenControl(POSTPRESERVATIONDATA=) (readonly)>>
这是结果:
Traceback (most recent call last):
File "C:/Documents/JMARTINEZ/My Various/PythonPrograms/Mechanize.py",line 77, in <module> br.form["username"]= username
File "C:\Python27\lib\site-packages\ClientForm.py", line 2895, in __setitem__control = self.find_control(name)
File "C:\Python27\lib\site-packages\ClientForm.py", line 3222, in find_control return self._find_control(name, type, kind, id, label, predicate, nr)
File "C:\Python27\lib\site-packages\ClientForm.py", line 3304, in _find_control raise AmbiguityError("more than one control matching "+description)ClientForm.AmbiguityError: more than one control matching name 'username'