Skip to main content
 首页 » 编程设计

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

2025年05月04日14zlslch

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