python - 使用 Python 的 "Scrapy"时出错

标签 python scrapy

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

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

最佳答案

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

使用 pip 或 download a Windows binary 等包管理器安装 twisted .

关于python - 使用 Python 的 "Scrapy"时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5319156/

相关文章:

python - 如何使用 Scrapy/Python 从条件下拉字段中获取值?

python - Kullback-Leibler 散度从高斯 pm,pv 到高斯 qm,qv

python - 如何在Scrapy中使用Xpath表达4位数字

python - 我无法在终端中打开 scrapy shell

从字符串中抓取 HtmlXPathSelector

python - Scrapy - 获得响应的时机

python - 在 Django 的父模型中更新 auto_now DateTimeField

python - 如何使用 Elasticsearch-dsl 在 Django 中进行并行测试?

Python MySQLdb 占位符语法

python - 按升序将元素添加到已排序的数组中