Как автоматически увеличить DOWNLOAD_DELAY от scrapy при обнаружении кода 500 в статусе ответа

#sort dataframe by col
sort.df <- with(df,  df[order(sortbythiscolumn) , ])

#can also sort by more than one variable: sort by col1 and then by col2
sort2.df <- with(df, df[order(col1, col2) , ])

#sort in reverse order
sort2.df <- with(df, df[order(col1, -col2) , ])
1
задан halfer 31 March 2019 в 13:54
поделиться

1 ответ

Вы можете расширить AutoThrottle промежуточное программное обеспечение, отвечающее за управление задержками, с помощью собственной политики:

# extensions.py

from scrapy.extensions.throttle import AutoThrottle

class ZombieThrottle(AutoThrottle):
    """start throttling when web page dies"""

    def _adjust_delay(self, slot, latency, response):
        """Define delay adjustment policy"""
        if response.status == 500:
            slot.delay = 60  # 1 minute

И включить его вместо используемого по умолчанию в settings.py:

# settings.py
EXTENSIONS = {
    'scrapy.extensions.throttle.AutoThrottle': None,
    'myspider.extensions.ZombieThrottle': 0,
}
0
ответ дан Granitosaurus 31 March 2019 в 13:54
поделиться
Другие вопросы по тегам:

Похожие вопросы: