Scrapy - 301重定向在shell中

Pix*_*ist 3 python scrapy web-scraping scrapy-shell

我找不到解决以下问题的方法.我正在使用Scrapy(最新版本),我正在尝试调试蜘蛛.使用scrapy shell https://jigsaw.w3.org/HTTP/300/301.html- >它不遵循重定向(它使用默认的蜘蛛来获取数据).如果我正在运行我的蜘蛛它跟随301 - 但我无法调试.

如何使shell遵循301以允许调试最终页面?

Gra*_*rus 10

Scrapy使用Redirect Middleware进行重定向,但是它没有在shell中启用.快速解决此问题:

scrapy shell "https://jigsaw.w3.org/HTTP/300/301.html"
fetch(response.headers['Location'])
Run Code Online (Sandbox Code Playgroud)

另外,为了调试你的蜘蛛你可能想要检查你的蜘蛛正在接收的响应:

from scrapy.shell import inspect_response
def parse(self, response)
    inspect_response(response, self)
    # the spider will stop here and open up an interactive shell during the run
Run Code Online (Sandbox Code Playgroud)