mechanize select form using id

后端 未结 7 1760
天命终不由人
天命终不由人 2020-12-18 18:31

I am working on mechanize with python.

The

7条回答
  •  盖世英雄少女心
    2020-12-18 18:44

    I found this as a solution for the same problem. br is the mechanize object:

    formcount=0
    for frm in br.forms():  
      if str(frm.attrs["id"])=="sblock":
        break
      formcount=formcount+1
    br.select_form(nr=formcount)
    

    I'm sure the loop counter method above could be done more pythonic, but this should select the form with attribute id="sblock".

提交回复
热议问题