Scrapy: catch responses with specific HTTP server codes

99封情书 提交于 2019-12-03 08:06:20
alecxe

By default, Scrapy only handles responses with status codes 200-300.

Let Scrapy handle 500 and 502:

class Spider(...):
    handle_httpstatus_list = [500, 502]

Then, in the parse() callback, check response.status:

def parse(response):
    if response.status == 500:
        # logic here
    elif response.status == 502:
        # logic here
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!