Home  >  Q&A  >  body text

python - 请问scrapy中如何设置request的重试次数

scrapy版本:1.1.2
python 版本:3.5

在使用scrapy抓取数据的时候使用了代理IP,难免会遇到代理IP失效的情况。

因为对数据完整性要求较高,请问如何设置只要没有成功的返回response则把任务重新放进Request队列中去继续爬取?

天蓬老师天蓬老师2741 days ago878

reply all(1)I'll reply

  • 阿神

    阿神2017-04-18 09:39:31

    You can use the one that comes with scrapyscrapy.downloadermiddlewares.retry.RetryMiddleware中间件,然后通过这几个参数进行配置:
    RETRY_ENABLED: 是否开启retry
    RETRY_TIMES: 重试次数
    RETRY_HTTP_CODECS: You need to retry when you encounter any http code. The default is 500, 502, 503, 504, 408. Other problems such as network connection timeout will also be automatically retried

    reply
    0
  • Cancelreply