Scrapy 如何在pipelines中获取爬虫名?

发布于 2022-09-11 19:29:40 字数 282 浏览 19 评论 0

需要在Pipeline获取到当前运行的爬虫name

spider.py

class Spider(scrapy.Spider):
    name = "xxxx"

pipelines.py

class spiderPipeline(object):
    def __init__(self):
        self.spidername = **?????**这里如何拿到当前爬虫name xxxxx?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

谁对谁错谁最难过 2022-09-18 19:29:40

spider.py

import scrapy


class QuotesSpider(scrapy.Spider):
    name = "quotes"

pipelines.py

from scrapy.crawler import _get_spider_loader


class TutorialPipeline(object):

    def __init__(self, settings):
        for name in _get_spider_loader(settings).list():
            self.spidername = name

    @classmethod
    def from_crawler(cls, crawler):
        return cls(crawler.settings)

    def process_item(self, item, spider):
        return item

run
scrapy crawl quotes

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文