【问题标题】:Mechanize: TypeError: 'NoneType' object does not support item assignment机械化:TypeError:“NoneType”对象不支持项目分配
【发布时间】:2016-10-17 02:40:00
【问题描述】:

尝试填写表格以获得城市商品的平均价格。

basket = br.open('http://www.numbeo.com/cost-of-living/')
read_it = basket.read()

# Select form
for form in br.forms():
    print '%r %r %s' % (form.name, form.attrs.get('id'), form.action)
    for control in form.controls:
        print ' ', control.type, control.name, repr(control.value)

br.form['menu_dispatch_form'] = 'Washington, DC, United States'
br.submit()

我收到此错误:

Traceback (most recent call last):
  File "Trip cost calculator/trip costs calculator.py", line 50, in <module>
    br.form['menu_dispatch_form'] = 'Washington, DC, United States'
TypeError: 'NoneType' object does not support item assignment

没有表单名称,但我想我可以使用表单 ID。我发现这个website 很有帮助,但与他们的示例不同,我没有任何text 可以放入br.form[]。有谁知道怎么回事?

【问题讨论】:

    标签: python mechanize


    【解决方案1】:

    你做错了。您需要选择一个form,然后才能为表单控件赋值​​。

    你有menu_dispatch_form吗?然后使用br.select_form("menu_dispatch_form") 选择表格。要将数据添加到表单,您应该为表单控件分配值。 Thisthis 应该可以帮助您查找和分配值给表单控件。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-10-30
      • 1970-01-01
      • 2016-07-31
      • 2014-02-18
      • 2017-03-26
      • 2021-08-05
      相关资源
      最近更新 更多