尝试填写表格以获取某个城市的商品平均价格。
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[]
。有谁知道发生了什么事?