Python 在Scrapy中是否可以从管道访问特定Spider的统计信息?

Python 在Scrapy中是否可以从管道访问特定Spider的统计信息?,python,web-scraping,scrapy,Python,Web Scraping,Scrapy,我将Scrapy与几个Spider一起使用,需要定制json输出,其中包括一些Spider统计信息(成功请求列表、错误列表等)。我已经制作了自定义项目管道,但我不知道如何从那里访问统计数据。这是到目前为止我的管道代码: class JsonWithEncodingPipeline(object): def open_spider(self, spider): self.file = codecs.open(spider.output_path, 'w', encodin

我将Scrapy与几个Spider一起使用,需要定制json输出,其中包括一些Spider统计信息(成功请求列表、错误列表等)。我已经制作了自定义项目管道,但我不知道如何从那里访问统计数据。这是到目前为止我的管道代码:

class JsonWithEncodingPipeline(object):

    def open_spider(self, spider):
        self.file = codecs.open(spider.output_path, 'w', encoding='utf-8')

    def process_item(self, item, spider):
        line = json.dumps(dict(item), ensure_ascii=False, indent=2) + "\n"
        self.file.write(line)
        return item

    def spider_closed(self, spider):
        self.file.close()

您可以访问如下统计信息:

class MyPipeline:

    def __init__(self, stats):
        self.stats = stats

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

你能告诉我们你发送请求的代码吗?