2015-06-04 6 views
6

Wir haben ein ziemlich Standard Scrapy Projekt (Scrapy 0,24).Scrapy: catch Antworten mit spezifischen HTTP-Server-Codes

Ich möchte bestimmten HTTP-Response-Codes, wie 200, 500, 502, 503, 504 usw.

So etwas fangen:

class Spider(...): 

    def parse(...): 
     processes HTTP 200 

    def parse_500(...): 
     processes HTTP 500 errors 

    def parse_502(...): 
     processes HTTP 502 errors 

    ... 

Wie wir das tun können?

Antwort

9

Standardmäßig verarbeitet Scrapy nur Antworten mit Statuscodes 200 - 300.

Let Scrapy handle 500 and 502:

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

Dann wird in der parse() Rückruf überprüfen response.status:

def parse(response): 
    if response.status == 500: 
     # logic here 
    elif response.status == 502: 
     # logic here