gpt4 book ai didi

python - 遇到第一个异常时,如何使scrapy crawl 中断并退出?

转载 作者:IT老高 更新时间:2023-10-28 20:53:46 51 4
gpt4 key购买 nike

出于开发目的,我想在第一个异常(在蜘蛛或管道中)发生后立即停止所有抓取事件。

有什么建议吗?

最佳答案

在蜘蛛中,你可以直接抛出 CloseSpider异常(exception)。

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

对于其他(中间件、管道等),您可以手动调用close_spider正如阿赫特所说。

关于python - 遇到第一个异常时,如何使scrapy crawl 中断并退出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9524923/

51 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com