1

我有这个代码:

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()
4

1 回答 1

1

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

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

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

注意:你有r1(不是r)在print

于 2013-08-05T09:55:10.357 回答