gpt4 book ai didi

python - Mechanize 从下拉列表中选择

转载 作者:行者123 更新时间:2023-12-01 04:40:00 24 4
gpt4 key购买 nike

我想 Mechanize 检查所选下拉列表的当前值是否=默认值,然后 Mechanize 将选择列表中的另一个值。下拉菜单的html如下:

            <td class="label">List</td>
<td>
<select name="list" id="list" onchange="list()">
<option>---</option>
<option value='1'>1</option>
<option value='2'>2</option>
---other options---

我的代码是:

if br.form["list"] == "---":
br.form["list"].value = "1"
r = br.form["list"]
print(r)

但是列表值仍然返回:

   ['---']

有什么想法吗?

最佳答案

您需要将值指定为列表:

if br.form["list"] == ["---"]:
br.form["list"].value = ["1"]

根据mechanize - Forms documentation :

# Controls that represent lists (checkbox, select and radio lists) are
# ListControl instances. Their values are sequences of list item names.
# They come in two flavours: single- and multiple-selection:
form["favorite_cheese"] = ["brie"] # single
form["cheeses"] = ["parmesan", "leicester", "cheddar"] # multi

关于python - Mechanize 从下拉列表中选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30934003/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com