Scrapy:AttributeError:' list'对象没有属性' iteritems'

时间:2016-05-25 16:27:24

标签: python scrapy-spider six

这是我关于堆栈溢出的第一个问题。最近我想使用linked-in-scraper,所以我下载并指示" scrapy crawl linkedin.com"并获取以下错误消息。为了您的信息,我使用anaconda 2.3.0和python 2.7.11。在执行程序之前,所有相关的包(包括scrapy和6)都会由pip更新。

PrintStruct

据我所知,这个错误源于d不是字典类型而是列表类型。而且由于错误来自scrapy上的代码,可能是scrapy包或六包上的问题。我该如何尝试修复此错误?

编辑:这是来自scrapy.cfg的代码

Traceback (most recent call last):
  File "/Users/byeongsuyu/anaconda/bin/scrapy", line 11, in <module>
    sys.exit(execute())
File "/Users/byeongsuyu/anaconda/lib/python2.7/site-packages/scrapy/cmdline.py", line 108, in execute
settings = get_project_settings()
File "/Users/byeongsuyu/anaconda/lib/python2.7/site-packages/scrapy/utils/project.py", line 60, in get_project_settings
settings.setmodule(settings_module_path, priority='project')
File "/Users/byeongsuyu/anaconda/lib/python2.7/site-packages/scrapy/settings/__init__.py", line 285, in setmodule
self.set(key, getattr(module, key), priority)
  File "/Users/byeongsuyu/anaconda/lib/python2.7/site-packages/scrapy/settings/__init__.py", line 260, in set
self.attributes[name].set(value, priority)
  File "/Users/byeongsuyu/anaconda/lib/python2.7/site-packages/scrapy/settings/__init__.py", line 55, in set
value = BaseSettings(value, priority=priority)
  File "/Users/byeongsuyu/anaconda/lib/python2.7/site-packages/scrapy/settings/__init__.py", line 91, in __init__
self.update(values, priority)
  File "/Users/byeongsuyu/anaconda/lib/python2.7/site-packages/scrapy/settings/__init__.py", line 317, in update
for name, value in six.iteritems(values):
  File "/Users/byeongsuyu/anaconda/lib/python2.7/site-packages/six.py", line 599, in iteritems
return d.iteritems(**kw)

AttributeError: 'list' object has no attribute 'iteritems'

2 个答案:

答案 0 :(得分:31)

这是由链接的刮刀settings

引起的
ITEM_PIPELINES = ['linkedIn.pipelines.LinkedinPipeline']

但是,ITEM_PIPELINES应该是dict,according to the doc

  

要激活项目管道组件,您必须将其类添加到ITEM_PIPELINES设置,如下例所示:

ITEM_PIPELINES = {
    'myproject.pipelines.PricePipeline': 300,
    'myproject.pipelines.JsonWriterPipeline': 800,
}
     

您在此设置中为类指定的整数值决定了它们运行的​​顺序:项目从较低值到较高值类别。习惯上在0-1000范围内定义这些数字。

根据this question,它曾经是一个列表,它解释了为什么这个刮刀使用列表。 因此,您必须要求刮刀的开发人员更新其代码,或者自己设置ITEM_PIPELINES

答案 1 :(得分:0)

简短的回答是ITEM_PIPELINES应该是一个字典,而不是一个列表,其中键作为管道类,并且值为一个整数,用于确定它们运行的​​顺序:项目从较低值到较高值类别。习惯上在0-1000范围内定义这些数字。正如@valentin Lorentz所解释的