[英]I am trying to print the 301 status for scrapy requests. But, the page redirects and shows 200 everytime
I am trying to print the 301 status for scrapy requests. 我正在尝试为scrapy请求打印301状态。 But, the page redirects and I get 200 status code every time. 但是,页面重定向,每次我得到200状态代码。 I do not want the redirection to happen and just print the 301 code. 我不希望发生重定向,仅打印301代码。 I am new to Scrapy and can not figure it out. 我是Scrapy的新手,无法解决。
I have the following code: enter image description here 我有以下代码: 在此处输入图片描述
You can use the meta attribute in your request, and you pass the key:value 您可以在请求中使用meta属性,然后传递key:value
class RedirectSpider(scrapy.Spider):
name = 'redirect'
url = 'http://www.wayfair.com/outdoor/sb0/fire-pits-c215964.html/'
def start_requests(self):
yield scrapy.Request(
url=self.url,
meta={'dont_redirect': True, 'handle_httpstatus_list': [301]},
callback=self.parse,
)
def parse(self, response):
print(response.status)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.