[英]Get All Spiders Class name in Scrapy
在旧版本中,我们可以使用以下代码获取蜘蛛列表(蜘蛛名称),但在当前版本(1.4)中,我遇到了
[py.warnings] WARNING: run-all-spiders.py:17: ScrapyDeprecationWarning: CrawlerRunner.spiders attribute is renamed to CrawlerRunner.spider_loader.
for spider_name in process.spiders.list():
# list all the available spiders in my project
使用crawler.spiders.list()
:
>>> for spider_name in crawler.spiders.list():
... print(spider_name)
如何在Scrapy中获取蜘蛛列表(和等效的类名)?
我在实用程序脚本中使用它来运行Spider:
from scrapy import spiderloader
from scrapy.utils import project
settings = project.get_project_settings()
spider_loader = spiderloader.SpiderLoader.from_settings(settings)
spiders = spider_loader.list()
classes = [spider_loader.load(name) for name in spiders]
在你的情况下,它应该足以命名spiders
给spider_loader
通过警告消息的建议。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.