如何使用Scrapy获取stat(item_scraped_count)?

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何使用Scrapy获取stat(item_scraped_count)?相关的知识,希望对你有一定的参考价值。

我想获得已删除项目的总计数,但我总是收到错误

from scrapy.stats import stats

class MySpider(Spider):
  name = "myspider"
  start_urls = ["http://example.com"]
  #Other Code


def close_spider(self, spider):
   stats.set_value('item_scraped_count')

我总是得到这个错误“Scrapy.stats已经过时使用crawler.stats”

我尝试了不同的代码,并在互联网上搜索,但我无法得到正确的答案,请帮助我

答案

All Good Now我只是使用https://doc.scrapy.org/en/latest/topics/stats.html中的这个

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

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

以上是关于如何使用Scrapy获取stat(item_scraped_count)?的主要内容,如果未能解决你的问题,请参考以下文章