scrapy_数据收集

什么是数据收集器?

       数据以key/value形式存在,收集一些状态,简化数据收集的状态

  计算到底发送了多少request等等统计信息

如何对404页面进行设置?

       通过response.status等于判断状态是否为404,然后把失败的URL添加到初始化的失败列表中,设置失败计数收集器

       在spider类逻辑中:

def __inint__(self):
    self.fail_urls = []                                   # 定义存储失败url列表

def parse(self, response):
    if response.status == 404:                            # 判断状态
        sefl.fail_urls.append(response.url)
        self.crawler.stats.inc_value(‘fail_urls’)         #设置失败信息收集器

  

  

原文地址:https://www.cnblogs.com/2bjiujiu/p/7371547.html