选择机械化表单中的未命名文本字段(python)
所以我正在制作一个程序,使用 mechanize 和 python 将街道地址批量转换为 GPS 坐标。这是我第一次使用机械化。我可以选择页面上的表单(“form2”)。但是表单中的文本框没有名称。如何选择文本框以便 mechanize 可以输入我的文本?我尝试通过其 id 选择它。但是这是行不通的
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>
我们将不胜感激。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
form.find_control(id="search")
?form.find_control(id="search")
?FWIW我通过使用lazy1的上述答案解决了这个问题,除了我试图在使用find_control方法后分配一个值。当然,由于分配的原因,这不起作用,我更深入地研究了该方法,发现 setattr() ,它非常适合为该字段分配值。
不会起作用
会起作用
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
will work