1

我在 Python 2.7 上安装了最新版本的 Scrapy(是的,我仍然使用这个版本)并且在运行 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

教程脚本在我的桌面上。会有这种效果吗?我应该把它放在不同的地方吗?

4

2 回答 2

5

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

使用 pip 之类的包管理器安装 twisted 或下载 Windows 二进制文件

于 2011-03-16T15:46:28.187 回答
2

您没有在 Windows 上成功安装 scrapy。以下步骤应该适用于您在 Windows 上安装 scrapy 0.14(latest)。

  1. 在此处使用 Windows 安装程序安装 lxml-2.3 。我尝试了 libxml 但不起作用。
  2. 在此处使用 Windows 安装程序安装 Twisted-12.0.0
  3. 是否使用 Mingw32 安装 zope.interface。
  4. 在此处使用 Windows 安装程序安装 pyOpenSSL 0.13
  5. 运行“ pip install scrapy ”,你准备好了!

希望能帮助到你。

于 2012-05-29T03:00:48.127 回答