【问题标题】:TypeError: ListControl, must set a sequence (python error)TypeError:ListControl,必须设置一个序列(python错误)
【发布时间】:2010-12-22 06:19:04
【问题描述】:

我正在使用 Python Mechanize 打开网站、填写表格并提交该表格。 其实很简单。 它一直有效,直到我遇到单选按钮和“选择”输入框。

br.open(url)
br.select_form(name="postmsg")
br.form['subject'] = "Is this good for the holidays? "
br.form['message'] = "I'm new to technology."
br.form['E'] = '0'
br.submit()

  br.form['E'] = '0'
  File "build/bdist.linux-x86_64/egg/ClientForm.py", line 2897, in __setitem__
  File "build/bdist.linux-x86_64/egg/ClientForm.py", line 2092, in __setattr__
  File "build/bdist.linux-x86_64/egg/ClientForm.py", line 2100, in _set_value
TypeError: ListControl, must set a sequence

为什么会出现此错误?为什么我不能像文本框一样设置E? (E 是单选按钮)

编辑:根据 Web Developer 的说法,这是表单。

Elements
Index   Id  Name    Type    Value   Label   Size    Maximum Length  State
0   subject subject text            35      
2   message message textarea                    
3   identity    identity    select          1       
13      action_btn  hidden                  
14      _charset_   hidden                  
16      r   hidden  /Stocks_(A_to_Z)/Stocks_G               
9       E   radio   0               

Checked
8       E   radio   1               
15      .crumb  hidden  1n1Yo3MQae3             
7       E   radio   2               
17      bn  hidden  25263               
6       E   radio   3               
5       E   radio   4               
4       E   radio   5               
12  SubmitCancel    SubmitCancel    submit  Cancel              
1   mbpostthreads   threads button  Check Existing Topics First             
11  SubmitPost  SubmitPost  submit  Post Message                
10  SubmitPreview   SubmitPreview   submit  Preview Message             
18  yIdCoreIdUser       hidden  annamae41g  

【问题讨论】:

  • 请提供单选按钮的 HTML

标签: python http url mechanize


【解决方案1】:

单选按钮和复选框的行为可能与其他元素不同。这取决于他们的姓名和身份证。

如果项目名称相同,请尝试这样做:

br.find_control(name="E").value = ["0"]

另一种选择是:

form.find_control(name="E", kind="list").value = ["0"]

最后,这可能会起作用:

    br["E"] = ["0"]

(我有一段时间没用过机械化,所以我记不太清了)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-12-26
    • 1970-01-01
    • 2018-12-14
    • 1970-01-01
    • 2021-08-30
    • 2016-05-09
    • 2015-08-04
    • 1970-01-01
    相关资源
    最近更新 更多