python - Obtaining the label of the control of a form in Mechanize -


i scrapping sites analyse every form within find general pattern allow me automate submitting search queries these sites. far, names of many of forms either non-existent or unclear, , need scrap associated label gain meaning controls (fields).

the mechanize support site states possible extract control form in web page when searching specific label:

control = form.find_control(label="select cheese") 

i looking solution obtain label control. documentation mechanize poor but answer question provides link more detailed documentation, have been unable find answer there.

has managed or found workaround solution?

i once had similar when automating data submission form. obtained list of names , labels of controls as:

names = []     labels = []      c in br.form.controls.__iter__():     names.append(c.name)     labels.append(c._label) 

with these lists can select form as:

control = form.find_control(name=names[0]) 

Comments