Python mechannize 'NoneType object has no attribute 'click()' with br.submit(name=s)

StackOverflow https://stackoverflow.com/questions/22109471

  •  18-10-2022
  •  | 
  •  

문제

what i'm trying to do is automate my browsing tasks using python mechanize there are four buttons with different names in the html form. I've selected the form using command br.select_form(nr=0). Now

s='NameofButton1'
br.submit(name=s)

is working good. But as i have to click on all the four buttons so i.m using for loop and the code goes like this

sBegin='NameofButton'
l=['1','2','3','4']
for item in l:
    s=sBegin+item
    br.submit(name=s)

is not working and giving error 'NoneType' object has no attribute 'click'.

도움이 되었습니까?

해결책

after you submit the fist button, your browser state will be redirected to result page.

so i suggest before you begin to submit your form, you should reopen the initial page where you can find those buttons

sBegin='NameofButton'
l=['1','2','3','4']
for item in l:
    s=sBegin+item
    br.open("url to initial page")
    br.submit(name=s)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top