Scrapy:在一个请求失败的情况下(例如404,500),如何请求另一个替代请求? [英] Scrapy:In a request fails (eg 404,500), how to ask for another alternative request?

查看:284
本文介绍了Scrapy:在一个请求失败的情况下(例如404,500),如何请求另一个替代请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有刮擦的问题. 在一个请求失败(例如404,500)时,如何请求另一个替代请求?例如两个链接可以获取价格信息,一个失败,自动请求另一个.

I have a problem with scrapy. In a request fails (eg 404,500), how to ask for another alternative request? Such as two links can obtain price info, the one failed, request another automatically.

推荐答案

在请求中使用"errback",例如 errback=self.error_handler 其中error_handler是一个函数(就像回调函数一样),在此函数中检查错误代码并发出替代请求.

Use "errback" in the Request like errback=self.error_handler where error_handler is a function (just like callback function) in this function check the error code and make the alternative Request.

请参阅scrapy文档中的errback: http://doc.scrapy.org/en/latest/topics/request -response.html

see errback in the scrapy documentation: http://doc.scrapy.org/en/latest/topics/request-response.html

这篇关于Scrapy:在一个请求失败的情况下(例如404,500),如何请求另一个替代请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆