3

So i'm making a program to batch convert street addresses to gps co-ordinates using mechanize and python. this is my first time using mechanize. I can select the form ("form2') on the page. however the text box in the form has no name. how do i select the textbox so that mechanize can enter my text? I've tried selecting it by its id. but that 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 much appreciated.

TritiumNZ
  • 31
  • 1
  • 2
  • Also, `select_form` for a name should be like this I think: `br.select_form(name="Form2")`, but maybe the function is overloaded to take a string... – Nick Merrill Mar 11 '13 at 02:37

2 Answers2

3

form.find_control(id="search") ?

Miki Tebeka
  • 13,428
  • 4
  • 37
  • 49
1

FWIW I solved this by using the above answer by lazy1 except that I was trying to assign a value after using the find_control method. That didn't work of course because of assignment, I looked deeper into the method and found setattr() and that worked great for assigning a value to to the field.

will not work

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

will work

br.form.find_control(id="field id here").__setattr__("value", "new value here")
aknatn
  • 673
  • 6
  • 14