【问题标题】:Scrapy Could not find spider ErrorScrapy找不到蜘蛛错误
【发布时间】:2010-05-22 00:57:46
【问题描述】:

我一直在尝试让一个简单的爬虫与scrapy一起运行,但不断收到错误:

Could not find spider for domain:stackexchange.com

当我使用表达式scrapy-ctl.py crawl stackexchange.com 运行代码时。蜘蛛如下:

from scrapy.spider import BaseSpider
from __future__ import absolute_import


class StackExchangeSpider(BaseSpider):
    domain_name = "stackexchange.com"
    start_urls = [
        "http://www.stackexchange.com/",
    ]

    def parse(self, response):
        filename = response.url.split("/")[-2]
        open(filename, 'wb').write(response.body)

SPIDER = StackExchangeSpider()`

另一个人几个月前发布了几乎完全相同的问题,但没有说明他们是如何解决的,Scrapy spider is not working 我一直在 http://doc.scrapy.org/intro/tutorial.html 关注教程,但不知道为什么它不起作用。

当我在 Eclipse 中运行此代码时,我得到了错误

Traceback (most recent call last): File "D:\Python Documents\dmoz\stackexchange\stackexchange\spiders\stackexchange_spider.py", line 1, in <module> from scrapy.spider import BaseSpider ImportError: No module named scrapy.spider

我无法弄清楚为什么它没有找到基本的 Spider 模块。我的蜘蛛必须保存在脚本目录中吗?

【问题讨论】:

  • 我的蜘蛛没有任何规则语句,所以我认为这不适用。不过我可能是错的。
  • 你在使用教程中定义的DmozSpider时是否也遇到同样的错误?
  • 我还没有尝试使用 dmoz 作为域。我真正做的只是改变它爬取的网站。
  • 你把上面贴的代码放在哪里了?我怀疑在 project/spiders 目录中找不到它,并且它没有被导入。如果是这样,您会收到一条错误消息,指出 from __future__ import absolute_import 行必须位于另一个导入行之前。

标签: python dns scrapy


【解决方案1】:

尝试运行python yourproject/spiders/domain.py 看看是否有任何语法错误。我认为您不应该启用绝对导入,因为scrapy 依赖于亲属导入。

【讨论】:

  • 它说找不到scrapy.spider模块
  • 是的,第一期说Could not find spider for domain:stackexchange.com 这是一条scrapy 消息,因此scrapy 模块可以正确加载。而后一个问题与eclipse和pythonpath有关。
  • 问题已修复。在另一台电脑上重新安装。一定是文件放错了地方或安装错误。
猜你喜欢
  • 1970-01-01
  • 2017-05-21
  • 1970-01-01
  • 2010-12-20
  • 2011-02-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多