因此,我正在编写一个程序,使用机械化和python将街道地址批量转换为gps坐标。这是我第一次使用机械化。我可以在页面上选择表格(“form2”)。但是表格中的文本框没有名字。我如何选择文本框使机械化可以输入我的文本?我试着按它的it选择它。但这不起作用。
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
这是该网站的源代码。
<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>
任何帮助都将不胜感激。
发布于 2011-01-24 23:39:26
form.find_control(id="search")
?
发布于 2014-08-20 06:23:34
除了我试图在使用find_control方法之后赋值之外,我通过使用lazy1的上述答案解决了这个问题。当然,由于赋值的原因,这不起作用,我更深入地研究了该方法,发现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")
https://stackoverflow.com/questions/4787907
复制