DOWNLOAD_FAIL_ON_DATALOSS = False scrapy 中settings 此项设置的含义和用法
DOWNLOAD_FAIL_ON_DATALOSS 用来控制当接收到的 response 头信息中的 Content-Length 和内容不匹配或者response chunk 未正确结束时的时所采取的操作。
当 DOWNLOAD_FAIL_ON_DATALOSS = True 的时候抛出 ResponseFailed([_DataLoss]) 错误
当设置为 DOWNLOAD_FAIL_ON_DATALOSS = False 时, 校验未通过的 response 将被忽略并且添加一个名为 dataloss 的 flag 到 response.flag
如果设置为 True :
scrapy.Request 有一个 errback 参数, 当 Request 请求出错的时候,会自动调用这个回调函数
如果设置为 False:
scrapy 会自动添加一个名为 dataloss 的 flag 到 response.flags, 用下面代码判断是否发生错误:
if 'dataloss' in response.flags: