how to handle 302 redirect in scrapy

后端 未结 6 499
时光说笑
时光说笑 2020-11-29 09:32

I am receiving a 302 response from a server while scrapping a website:

2014-04-01 21:31:51+0200 [ahrefs-h] DEBUG: Redirecting (302) to 

        
6条回答
  •  猫巷女王i
    2020-11-29 10:06

    Forgot about middlewares in this scenario, this will do the trick:

    meta = {'dont_redirect': True,'handle_httpstatus_list': [302]}
    

    That said, you will need to include meta parameter when you yield your request:

    yield Request(item['link'],meta = {
                      'dont_redirect': True,
                      'handle_httpstatus_list': [302]
                  }, callback=self.your_callback)
    

提交回复
热议问题