【问题标题】:Selecting an unnamed text field in a mechanize form (python)在机械化表单中选择未命名的文本字段(python)
【发布时间】:2014-08-20 14:23:33
【问题描述】:

所以我正在制作一个程序,使用 mechanize 和 python 将街道地址批量转换为 gps 坐标。这是我第一次使用机械化。我可以在页面上选择表单(“form2”)。但是表单中的文本框没有名称。我如何选择文本框以便机械化可以输入我的文本?我尝试通过它的 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>

任何帮助将不胜感激。

【问题讨论】:

  • 另外,select_form 的名称应该是这样的,我认为:br.select_form(name="Form2"),但可能函数被重载以获取字符串...

标签: python forms automation mechanize


【解决方案1】:

form.find_control(id="search")?

【讨论】:

    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 2015-02-13
      • 2013-01-12
      • 1970-01-01
      • 1970-01-01
      • 2012-05-16
      • 1970-01-01
      • 2017-01-19
      • 2015-05-07
      • 1970-01-01
      相关资源
      最近更新 更多