使用Python的“Scrapy”错误

问题描述:

我在Python 2.7上安装了最新版本的Scrapy(是的,我仍然使用这个版本),并且在运行Scrapy的教程脚本时出现错误。 我跑的代码是:使用Python的“Scrapy”错误

from scrapy.spider import BaseSpider 

class DmozSpider(BaseSpider): 
    name = "dmoz.org" 
    allowed_domains = ["dmoz.org"] 
    start_urls = [ 
     "http://www.dmoz.org/Computers/Programming/Languages/Python/Books/", 
     "http://www.dmoz.org/Computers/Programming/Languages/Python/Resources/" 
    ] 

    def parse(self, response): 
     filename = response.url.split("/")[-2] 
     open(filename, 'wb').write(response.body) 

的错误是:

Traceback (most recent call last): 
    File "C:/Users/Rainey/Desktop/dmoz/spiders/dmoz_spider.py", line 1, in <module> 
    from scrapy.spider import BaseSpider 
    File "C:\Python27\lib\site-packages\scrapy\spider.py", line 7, in <module> 
    from scrapy import log 
    File "C:\Python27\lib\site-packages\scrapy\log.py", line 10, in <module> 
    from twisted.python import log 
ImportError: No module named twisted.python 

教程脚本是我的桌面上。这种效果是否可以,我应该在不同的地方吗?

错误消息'ImportError:No module named twisted.python'表示您缺少twisted模块。

使用像pip或download a Windows binary这样的包管理器来安装扭曲。

您未在Windows上成功安装scrapy。以下步骤应该适用于您在Windows上安装scrapy 0.14(最新版本)。

  1. 使用Windows安装程序安装lxml-2.3 here。我试过libxml,但没有工作。
  2. 使用windows安装程序安装Twisted-12.0.0 here
  3. 使用Mingw32安装zope.interface或不安装。
  4. 安装pyOpenSSL 0.13使用Windows Installer here
  5. 运行 “PIP安装scrapy”,你准备好了!

希望它有帮助。

+0

Zope接口https://pypi.python.org/pypi/zope.interface#download – fedmich 2013-03-26 10:58:07