ImportError:使用Scrapy时无法导入名称replace_entities错误

时间:2014-09-28 01:15:32

标签: python html web-scraping scrapy screen-scraping

在过去,我会通过写作来创造一个使用scrapy的蜘蛛 scrapy startproject some_project

最近,我克隆了一个有蜘蛛的存储库,现在当我导航到正确的位置并输入时 scrapy crawl some_spider -o output.csv -t csv
我收到导入错误:

    Traceback (most recent call last):
  File "/usr/local/bin/scrapy", line 3, in <module>
    from scrapy.cmdline import execute
  File "/usr/lib/pymodules/python2.7/scrapy/__init__.py", line 58, in <module>
    from scrapy.selector import Selector
  File "/usr/lib/pymodules/python2.7/scrapy/selector/__init__.py", line 4, in <module>
    from scrapy.selector.unified import *
  File "/usr/lib/pymodules/python2.7/scrapy/selector/unified.py", line 7, in <module>
    from scrapy.utils.misc import extract_regex
  File "/usr/lib/pymodules/python2.7/scrapy/utils/misc.py", line 8, in <module>
    from w3lib.html import replace_entities
ImportError: cannot import name replace_entities

我用Google搜索并试图了解`replace_entities&#39;但我无法找到任何信息。任何关于为什么会出现这些导入错误的帮助以及如何解决这个问题的任何想法都将非常感激。

1 个答案:

答案 0 :(得分:2)

w3libScrapy的依赖关系,引自setup.py(版本0.24.4):

install_requires=[
    'Twisted>=10.0.0',
    'w3lib>=1.8.0',
    'queuelib',
    'lxml',
    'pyOpenSSL',
    'cssselect>=0.9',
    'six>=1.5.2',
],

如您所见,Scrapy要求w3lib为1.8.0或更高版本。

解决方案是升级w3lib包:

pip install --upgrade w3lib