使用mechanize提交表单,[TypeError:ListControl,必须设置序列]

时间:2014-04-23 11:57:21

标签: python python-2.7 mechanize autofill

例如,

让我们在facebook注册页面上尝试提交注册表单:

br.set_handle_robots(False) 
br.open('http://www.facebook.com/r.php')
print br.response()
for f in br.forms():
    print f

br.select_form(nr=1) 
br['firstname']='watever' 
br['lastname']='Kafle'
br['reg_passwd__']='abhibandu'
br['reg_email__']='watever@gmail.com'
br['reg_email_confirmation__']='watever@gmail.com'
br['birthday_month']='01'
br['birthday_day']='20'
br['birtday_year']='1990'
br['sex']='2'
br.submit()

print br.response()

Q1)我得到" TypeError:ListControl,必须设置序列"错误。我做错了吗?

Q2)P.S。有人还建议如何在表单提交后每次重新加载/刷新页面(如果我想创建多个fb帐户)?

提前致谢!

以下是我收到的错误消息:

Traceback (most recent call last):
  File "C:\Users\ninja\Desktop\facebookautofill\test.py", line 15, in <module>
    br['birthday_month']='01'
  File "C:\Python27\lib\site-packages\mechanize-0.2.5-py2.7.egg\mechanize\_form.py", line 2782, in __setitem__
    control.value = value
  File "C:\Python27\lib\site-packages\mechanize-0.2.5-py2.7.egg\mechanize\_form.py", line 1977, in __setattr__
    self._set_value(value)
  File "C:\Python27\lib\site-packages\mechanize-0.2.5-py2.7.egg\mechanize\_form.py", line 1985, in _set_value
    raise TypeError("ListControl, must set a sequence")
TypeError: ListControl, must set a sequence

当我在Submitting a form with mechanize (TypeError: ListControl, must set a sequence)

更新月份日和年份时
br['birthday_month']=['01',]
br['birthday_day']=['20',]
br['birtday_year']=['1990',]

我现在得到以下错误:

Traceback (most recent call last):
  File "C:\Users\ninja\Desktop\facebookautofill\test.py", line 15, in <module>
    br['birthday_month']=['01',]
  File "C:\Python27\lib\site-packages\mechanize-0.2.5-py2.7.egg\mechanize\_form.py", line 2782, in __setitem__
    control.value = value
  File "C:\Python27\lib\site-packages\mechanize-0.2.5-py2.7.egg\mechanize\_form.py", line 1977, in __setattr__
    self._set_value(value)
  File "C:\Python27\lib\site-packages\mechanize-0.2.5-py2.7.egg\mechanize\_form.py", line 1998, in _set_value
    self._single_set_value(value)
  File "C:\Python27\lib\site-packages\mechanize-0.2.5-py2.7.egg\mechanize\_form.py", line 2021, in _single_set_value
    on, off = self._get_items(value[0])
  File "C:\Python27\lib\site-packages\mechanize-0.2.5-py2.7.egg\mechanize\_form.py", line 2006, in _get_items
    "insufficient items with name %r" % name)
ItemNotFoundError: insufficient items with name '01'

0 个答案:

没有答案