python-类InstagramSpider(scrapy.Spider):AttributeError:’模块’对象没有属性’Spider’

我该如何解决该错误?

[email protected]:~/computer_vision/instagram/instagram$scrapy crawl instagramspider
2017-03-01 17:24:03-0600 [scrapy] INFO: Scrapy 0.14.4 started (bot: instagram)
2017-03-01 17:24:04-0600 [scrapy] DEBUG: Enabled extensions: LogStats, TelnetConsole, CloseSpider, WebService, CoreStats, MemoryUsage, SpiderState
Traceback (most recent call last):
  File "/usr/bin/scrapy", line 4, in 
    execute()
  File "/usr/lib/python2.7/dist-packages/scrapy/cmdline.py", line 132, in execute
    _run_print_help(parser, _run_command, cmd, args, opts)
  File "/usr/lib/python2.7/dist-packages/scrapy/cmdline.py", line 97, in _run_print_help
    func(*a, **kw)
  File "/usr/lib/python2.7/dist-packages/scrapy/cmdline.py", line 139, in _run_command
    cmd.run(args, opts)
  File "/usr/lib/python2.7/dist-packages/scrapy/commands/crawl.py", line 43, in run
    spider = self.crawler.spiders.create(spname, **opts.spargs)
  File "/usr/lib/python2.7/dist-packages/scrapy/command.py", line 34, in crawler
    self._crawler.configure()
  File "/usr/lib/python2.7/dist-packages/scrapy/crawler.py", line 36, in configure
    self.spiders = spman_cls.from_crawler(self)
  File "/usr/lib/python2.7/dist-packages/scrapy/spidermanager.py", line 37, in from_crawler
    return cls.from_settings(crawler.settings)
  File "/usr/lib/python2.7/dist-packages/scrapy/spidermanager.py", line 33, in from_settings
    return cls(settings.getlist('SPIDER_MODULES'))
  File "/usr/lib/python2.7/dist-packages/scrapy/spidermanager.py", line 23, in __init__
    for module in walk_modules(name):
  File "/usr/lib/python2.7/dist-packages/scrapy/utils/misc.py", line 65, in walk_modules
    submod = __import__(fullpath, {}, {}, [''])
  File "/home/mona/computer_vision/instagram/instagram/instagram/spiders/spider.py", line 7, in 
    class InstagramSpider(scrapy.Spider):
AttributeError: 'module' object has no attribute 'Spider'

更多信息可以在这里找到:
From scraper_user.items import UserItem ImportError: No module named scraper_user.items

Python 2.7.6 (default, Oct 26 2016, 20:30:19) 
[GCC 4.8.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import scrapy
>>> print scrapy.__file__
/usr/lib/python2.7/dist-packages/scrapy/__init__.pyc
>>> print(dir(scrapy))
['__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__', '__version__', 'boto', 'optional_features', 'os', 'sys', 'twisted_250_monkeypatches', 'urlparse_monkeypatches', 'version_info', 'warnings', 'xlib']
>>> print(scrapy.spider)
Traceback (most recent call last):
  File "", line 1, in 
AttributeError: 'module' object has no attribute 'spider'

最佳答案

根据输出,您使用的是非常老的Scrapy 0.14.4,它没有将Spider暴露在scrapy命名空间上.

可以更新:

pip install scrapy --upgrade

或者,将您的导入更改为(不确定这将照原样工作):

from scrapy.spider import BaseSpider as Spider