gpt4 book ai didi

Python Mechanize 表单下拉错误

转载 作者:太空宇宙 更新时间:2023-11-03 18:52:17 25 4
gpt4 key购买 nike

我有这个代码:

br.open(url)
br.select_form(nr=0)

br.form['mydropdown'] = 1
r = br.submit()
print r1.read()

我尝试提交的表单的 HTML 是:

<select name="mydropdown">
<option value="1">Cake</option>
<option value="2">Apple</option>
<option value="3">Muffin</option>

为什么我收到此错误:

Traceback (most recent call last):
File "***", line 9, in <module>
br.form['dropdown'] = 1
File "***", line 2782, in __setitem__
control.value = value
File "***", line 1977, in __setattr__
self._set_value(value)
File "***", line 1993, in _set_value
elif len(value) > 1:
TypeError: object of type 'int' has no len()

最佳答案

你应该像这样解析你的选择:

br.open(url)
br.select_form(nr=0)

br.form['mydropdown'] = ["1"]
r = br.submit()
print r.read()

注意:print 中有 r1 (不是 r)

关于Python Mechanize 表单下拉错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18055233/

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