我有这段代码:
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()
答案 0 :(得分:1)
您应该像这样解析您的选择:
br.open(url)
br.select_form(nr=0)
br.form['mydropdown'] = ["1"]
r = br.submit()
print r.read()
注意:r1
r
(不是print
)