gpt4 book ai didi

python - Scrapy Spider 关闭后如何获取 `item_scraped_count` - Python27

转载 作者:行者123 更新时间:2023-12-03 21:32:21 26 4
gpt4 key购买 nike

每当 s Spider 完成时,scrapy 会在终端/CLI 中显示这一点。

{'downloader/exception_count': 2,
'downloader/exception_type_count/twisted.internet.error.TimeoutError': 2,
'downloader/request_bytes': 58010,
'downloader/request_count': 157,
'downloader/request_method_count/GET': 157,
'downloader/response_bytes': 1151051,
'downloader/response_count': 155,
'downloader/response_status_count/200': 136,
'downloader/response_status_count/403': 19,
'file_count': 9,
'file_status_count/downloaded': 1,
'file_status_count/uptodate': 8,
'finish_reason': 'finished',
'finish_time': datetime.datetime(2016, 12, 23, 15, 8, 36, 325285),
'item_scraped_count': 10,
'log_count/DEBUG': 203,
'log_count/ERROR': 57,
'log_count/INFO': 289,
'log_count/WARNING': 1354,
'request_depth_max': 3,
'response_received_count': 135,
'scheduler/dequeued': 156,
'scheduler/dequeued/memory': 156,
'scheduler/enqueued': 156,
'scheduler/enqueued/memory': 156,
'spider_exceptions/AttributeError': 1,
'start_time': datetime.datetime(2016, 12, 23, 15, 0, 9, 832308)}

但是我想在蜘蛛运行完成后以代码访问整个字典。每当蜘蛛完成运行时,我都会执行此方法。
def spider_closed(self, spider):
stats = spider.crawler.stats.get_stats()
self.logger.info("Spider is being closed")
self.logger.info(stats)

它的输出不包括 item_scraped_count ,而它的输出对我来说非常无用。它的输出是
{'log_count/DEBUG': 40, 'scheduler/dequeued': 28, 'log_count/INFO': 74, 'downloader/response_count': 28, 'downloader/response_status_count/200': 24, 'response_received_count': 28, 'scheduler/enqueued/memory': 425, 'downloader/response_bytes': 273395, 'finish_reason': 'shutdown', 'start_time': datetime.datetime(2016, 12, 23, 18, 20, 21, 580932), 'scheduler/dequeued/memory': 28, 'scheduler/enqueued': 425, 'downloader/response_status_count/403': 4, 'finish_time': datetime.datetime(2016, 12, 23, 18, 21, 20, 867566), 'downloader/request_bytes': 9566, 'request_depth_max': 2, 'log_count/WARNING': 1, 'downloader/request_method_count/GET': 28, 'downloader/request_count': 28}

最佳答案

我认为这可能是因为自 finish_reason 以来运行被中断或终止(?)是 shutdown而不是 finished在你的最后一个例子中。也许根本没有抓取任何元素,这就是为什么没有 item_scraped_count key ?

关于python - Scrapy Spider 关闭后如何获取 `item_scraped_count` - Python27,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41306669/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com