python - ClientForm.AmbiguityError: more than one control matching name -
i new programming in python , trying login private website mechanize;i read similar questions like: how bypass mechanize "ambiguityerror" in python, python mechanize handle 2 parameters same name, non of these , there no feedback on solution second link. far i've read, using br.select_form(nr=0) should enough select first form still stuck; i've tried changing br.select_form(name of form) , br.form.find_control() attributeerror: 'nonetype' object has no attribute 'find_control'; options without success. below code , list of forms can found. support appreciated. thanks
this code used:
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()
these forms:
<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 me") (readonly)> <hiddencontrol(postpreservationdata=) (readonly)>>
this result:
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 1 control matching "+description)clientform.ambiguityerror: more 1 control matching name 'username'
it looks there 1 form code provided , multiple username, passwords fields ambiguous error comes from. use index parameter did selecting form, this:
br.select_form(nr=0) userone = br.find_control(name="username", nr=0) userone.value = "myusername" pwone = br.find_control(name="password", nr=0) pwone.value = "mypassword" br.submit()
Comments
Post a Comment