【问题标题】:Python Mechanize: how to select a dropdown list when two have the same name in web page?Python Mechanize:当网页中有两个同名时如何选择一个下拉列表?
【发布时间】:2011-09-18 04:33:15
【问题描述】:

我试图进行机械化解析的 html 是:

<select id="topic_id2" name="topics[]" title="blabla" tabindex="4" class="createSelect">
here go options

但是在它的正下方有另一个下拉菜单,代码如下:

<select id="topic_id3" name="topics[]" title="optional" tabindex="5" class="createSelect">

现在,如果它有帮助,我不需要从后者中选择任何值,因为它是可选的。

当我尝试时

br = mechanize.Browser()
br.select_form(name="form")
br["topics[]"] = ["Internet"]

我明白了:

mechanize._form.AmbiguityError: more than one control matching name 'topics[]'

有没有一种方法可以根据控件的 id 选择控件,使用 mechanize.Browser()(同时保留所有其他表单语法)?

谢谢

【问题讨论】:

标签: python mechanize


【解决方案1】:

mechanize 的外部文档非常小,仅包含几个示例,但代码内文档要广泛得多。

没有对此进行测试,使用名为formHTMLForm 实例,您应该能够调用form.find_control(id="topic_id3") 并得到您想要的。我不确定如何仅使用 Browser 对象来执行此操作,但是您尝试过 br.find_control(id="topic_id3") 吗?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-04
    • 2014-01-12
    • 2016-12-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多