5
,我试图使机械化解析HTML是:Python机械化:如何选择一个下拉列表,当两个在网页中具有相同的名称?
<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()(同时保留所有其他形式语法)?
感谢
你可以通过它们的索引在窗体中访问控件,看到这个答案http://stackoverflow.com/questions/6482308/differentiating-between-html-form-select-items-with-the-same-name/ 6483458#6483458 – cerberos
非常感谢,这工作。 –
你能在链接中给出答案吗? – cerberos