Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/345.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python scrapy spider名称定义和/或限制_Python_Scrapy - Fatal编程技术网

Python scrapy spider名称定义和/或限制

Python scrapy spider名称定义和/或限制,python,scrapy,Python,Scrapy,使用具有以下特性的scrapy示例: *.py中的星形符号编码为 class ArticleSpider(spider): name="article" 当我运行scrapy check-l或scrapy crawl article时,我得到一个错误: class ArticleSpider(spider): NameError: name 'spider' is not defined 我改为Spider,scrapy.Spider等,收到了相同的错误。我在scrapy.o

使用具有以下特性的scrapy示例: *.py中的星形符号编码为

class ArticleSpider(spider):
    name="article"
当我运行
scrapy check-l
scrapy crawl article
时,我得到一个错误:

    class ArticleSpider(spider):
NameError: name 'spider' is not defined

我改为
Spider
scrapy.Spider
等,收到了相同的错误。我在scrapy.org等网站上查看了(spider)的定义和/或限制,但没有找到任何。那么是什么导致了这个错误呢?

这个错误不是关于Spider名称的,而是来自您从中继承的类。也就是说:

您必须从蜘蛛继承:

from scrapy.spiders import Spider
然后:

请注意,类名区分大小写

如需更多信息,请参阅:


这不是一个小错误。这不是理解Python的基本原理。当找不到变量时,将引发
namererror
。我强烈建议您在开始使用Scrapy之前,先阅读Python的基础知识,并对其进行深入了解。在我正确拼写from语句后,它运行正常。谢谢作为参考,Bob@Yankee26太好了!如果你认为我的答案是正确的,请把它作为你问题的答案。
class ArticleSpider(Spider):
    name="article"