Scrapy 自动重定向如何解决

如遇到下图这种情况,即重定向问题(meta中携带:redirect_urls):

 

 可以通过在meta中添加'dont_redirect': True,'handle_httpstatus_list': [301,302] 来解决

    def start_requests(self):
        for area in self.area_list:
            data = 'searchBean.displayFlag=0&searchBean.listFlag=&jumpflag=2&conditionHtml=&searchBean.con1=&searchBean.con4={}&searchBean.con5=&searchBean.con2=&searchBean.con3=&searchBean.con8=&searchBean.con6=&jumpPage=2&page=1'.format(area)
            yield scrapy.Request(self.start_url, dont_filter=True, method='POST', headers=self.json_headers, body=data,meta={'area':area,'dont_redirect': True,
                'handle_httpstatus_list': [301,302]})

 

posted @ 2022-07-28 19:55  Eliphaz  阅读(575)  评论(0编辑  收藏  举报