简体   繁体   English

我正在尝试为scrapy请求打印301状态。 但是,页面重定向并每次显示200

[英]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

  • 'dont_redirect':'True 'dont_redirect':'真实
  • 'handle_httpstatus_list': [301] 'handle_httpstatus_list':[301]

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.

相关问题 尝试使用请求时,我收到 419 页过期状态代码。 我如何成功登录? - I'm receiving a 419 page expired status code when trying to use requests. How do I successfully login? 请求库有200个响应状态,但Scrapy有500个响应状态 - 200 response status with requests library but 500 with Scrapy 我正在尝试使用python通过请求将数据提交到网站。 如何通过确认对话框? - Using python i am trying to submit data to a website via requests. How to pass the confirmation dialog? Python Scrapy 301重定向 - Python Scrapy 301 redirects Python请求标头显示“ 301”,而获取返回“ 200” - Python requests head shows “301” while get returns “200” 如何停止scrapy 301重定向并停止解析重定向的页面 - how to stop scrapy 301 redirects and stop parsing the redirected page 仅从网站获取 JSON 的一部分,我正在尝试使用 Python、BeautifulSoup、请求来抓取。 从 62 条回复中获得 20 条回复 - Only getting a portion of JSON from website I am trying to scrape using Python, BeautifulSoup, Requests. Getting 20 responses out of 62 链接状态代码200重定向 - Link with status code 200 redirects 错误 429,请求过多。 当我试图让我的 python discord 24/7 重复时 - Error 429, Too many requests. When I was trying to keep my python discord 24/7 on replit Python 请求返回 200 而不是 301 - Python requests returns 200 instead of 301
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM