【发布时间】:2015-10-05 00:47:42
【问题描述】:
我是编程新手,正在尝试学习scrapy,使用scrapy教程:http://doc.scrapy.org/en/latest/intro/tutorial.html
所以我运行了“scrapy crawl dmoz”命令并得到了这个错误:
2015-07-14 16:11:02 [scrapy] INFO: Scrapy 1.0.1 started (bot: tutorial)
2015-07-14 16:11:02 [scrapy] INFO: Optional features available: ssl, http11
2015-07-14 16:11:02 [scrapy] INFO: Overridden settings: {'NEWSPIDER_MODULE': 'tu
torial.spiders', 'SPIDER_MODULES': ['tutorial.spiders'], 'BOT_NAME': 'tutorial'}
2015-07-14 16:11:05 [scrapy] INFO: Enabled extensions: CloseSpider, TelnetConsol
e, LogStats, CoreStats, SpiderState
Unhandled error in Deferred:
2015-07-14 16:11:06 [twisted] CRITICAL: Unhandled error in Deferred:
2015-07-14 16:11:07 [twisted] CRITICAL:
我使用的是 Windows 7 和 python 2.7。有人知道有什么问题吗?我该如何解决?
编辑:我的蜘蛛文件代码是:
# This package will contain the spiders of your Scrapy project
#
# Please refer to the documentation for information on how to create and manage
# your spiders.
import scrapy
class DmozSpider(scrapy.Spider):
name = "dmoz"
allowed_domains = ["dmoz.org"]
start_urls = [
"http://www.dmoz.org/computers/programming/languages/python/books/",
"http://www.dmoz.org/computer/programming/languages/python/resources/"
]
def parse(self, response):
filename = response.url.split("/")[-2] + '.html'
with open(filename,'wb') as f:
f.write(response.body)
items.py 代码:
import scrapy
class DmozItem(scrapy.Item):
title = scrapy.Field()
link = scrapy.Field()
desc = scrapy.Field()
点子列表:
- 引导管理 (0.3.3)
- cffi (1.1.2)
- 特征 (14.3.0)
- 密码学 (0.9.3)
- cssselect (0.9.1)
- Django (1.7.7)
- django-auth-ldap (1.2.4)
- django-debug-toolbar (1.3.0)
- django-mssql (1.6.2)
- django-pyodbc (0.2.6)
- django-pyodbc-azure (1.2.2)
- django-redator (0.2.3)
- django-reversion (1.8.5)
- django-summernote (0.6.0)
- django-windows-tools (0.1.1)
- django-wysiwyg-redactor (0.4.3.2)
- enum34 (1.0.4)
- ez 设置 (0.9)
- flup (1.0.2)
- idna (2.0)
- ipaddress (1.0.13)
- iso8601 (0.1.4)
- 日志记录 (0.4.9.6)
- lxml (3.4.4)
- 机械化 (0.2.5)
- MySQL-python (1.2.4)
- pbr (0.10.8)
- 枕头 (2.7.0)
- 点 (7.1.0)
- pyasn1 (0.1.8)
- pyasn1-modules (0.0.6)
- pycparser (2.14)
- pymongo (2.6)
- pyodbc (3.0.7)
- pyOpenSSL (0.15.1)
- pypm (1.4.3)
- python-ldap (2.4.18)
- pythonselect (1.3)
- pywin32 (218.3)
- queuelib (1.2.2)
- Scrapy (1.0.1)
- 硒 (2.44.0)
- 服务标识 (14.0.0)
- 设置工具 (18.0.1)
- 六(1.9.0)
- sqlparse (0.1.15)
- 码头工人 (1.3.0)
- 扭曲 (15.2.1)
- virtualenv (1.11.6)
- virtualenv 克隆 (0.2.5)
- virtualenvwrapper (4.3.2)
- virtualenvwrapper-powershell (12.7.8)
- w3lib (1.11.0)
- xlrd (0.9.2)
- zope.interface (4.1.2)
感谢您的关注,并为我糟糕的英语感到抱歉,这不是我的母语。
【问题讨论】:
-
请显示您的蜘蛛文件的代码。
-
我用蜘蛛代码更新了这个问题,弗兰克。我尝试复制并粘贴教程代码并自己输入,都产生了相同的错误。提请您注意。
-
感谢您发布代码。这是文件的完整内容吗?我不得不在文件的开头添加
import scrapy并修复缩进并且您的错误没有弹出。请准确发布您的蜘蛛文件的内容 - 小的差异很重要(甚至可能是错误的原因) -
我的错,更新了整个代码。无论如何,如果您只是添加“import scrapy”并修复标识,您认为这可能是缺少任何安装吗?
-
该错误看起来与缺少安装无关。我的怀疑是
item的定义。您是否已经按照教程的建议编辑了items.py?
标签: python-2.7 scrapy scrapy-spider