Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mechanize select form using id

Tags:

I am working on mechanize with python.

<form action="/monthly-reports"  accept-charset="UTF-8" method="post" id="sblock"> 

The form here does not have a name. How can I parse the form using it's id?

like image 547
sam Avatar asked May 08 '12 08:05

sam


1 Answers

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".

like image 56
python412524 Avatar answered Oct 01 '22 23:10

python412524