选择机械化表单中的未命名文本字段(python)

发布于 2024-10-14 05:34:03 字数 599 浏览 4 评论 0原文

所以我正在制作一个程序,使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一笑百媚生 2024-10-21 05:34:03

form.find_control(id="search")

form.find_control(id="search") ?

萌吟 2024-10-21 05:34:03

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")

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")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文