How can I make scrapy crawl break and exit when encountering the first exception?

前端 未结 3 923
伪装坚强ぢ
伪装坚强ぢ 2020-12-14 02:20

For development purposes, I would like to stop all scrapy crawling activity as soon a first exception (in a spider or a pipeline) occurs.

Any advice?

3条回答
  •  情书的邮戳
    2020-12-14 02:52

    In spider, you can just throw CloseSpider exception.

    def parse_page(self, response):
        if 'Bandwidth exceeded' in response.body:
            raise CloseSpider('bandwidth_exceeded')
    

    For others (middlewares, pipeline, etc), you can manually call close_spider as akhter mentioned.

提交回复
热议问题