Mechanizer in python - selecting form field with no name

て烟熏妆下的殇ゞ 提交于 2019-12-05 22:28:54

According to your code:

url = "www.example.com"
request = urllib2.Request(url, None, hdr)
response = br.open(request)
forms =  [form for form in br.forms()][0]
br.select_form(nr=0)

Following this:

aux = 0
for f in br.form.controls:
    print f,
    print '   ---> Number: ',
    print aux
    aux = aux + 1 

The results is:

<TextControl(<None>=)>   ---> Number:  0 
<PasswordControl(<None>=)>   ---> Number:  1
<CheckboxControl(<None>=[on])>   ---> Number:  2
<SubmitButtonControl(<None>=) (readonly)>   ---> Number:  3

Now, you can try this:

br.form.controls[0]._value = "loginname"
br.form.controls[1]._value = "password"

So:

for f in br.form.controls:
    print f

The results will be:

<TextControl(<None>=loginname)>
<PasswordControl(<None>=password)>
<CheckboxControl(<None>=[on])>
<SubmitButtonControl(<None>=) (readonly)>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!