Choosing an unnamed text field in a mechanization form (python)

So, I am making a program for batch converting street addresses to gps coordinates using mechanize and python. this is my first time using mechanization. I can select the form ("form2") on the page, but the text box on the form does not have a name. How to choose a text field so that mechanization can enter my text? I tried to select it by its identifier. this does not work.

br.select_form("Form2") #works as far as i know
br.form["search"] = ["1 lakewood drive, christchurch"] #this is the field that i cannot select

and here is the source code from the website.

<form name="Form2" >
or  Type an <b>Address</b>
<input id="search" size="40" type="text" value=""  >
<input type="button" onClick="EnteredAddress();" value="Enter" />
</form>

any help would be greatly appreciated.

+3
source share
2 answers

form.find_control(id="search")?

+3
source

FWIW , lazy1, , find_control. , - , setattr() .

br.form.find_control(id="field id here") = "new value here"

br.form.find_control(id="field id here").__setattr__("value", "new value here")
+1

Source: https://habr.com/ru/post/1787575/


All Articles