2011-03-15 75 views
1

我在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 

教程腳本是我的桌面上。這種效果是否可以,我應該在不同的地方嗎?

回答

5

錯誤消息'ImportError:No module named twisted.python'表示您缺少twisted模塊。

使用像pip或download a Windows binary這樣的包管理器來安裝扭曲。

2

您未在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