我找不到以下问题的解决方案。我正在使用 Scrapy(最新版本)并尝试调试蜘蛛。
使用 scrapy shell https://jigsaw.w3.org/HTTP/300/301.html
-> 它不遵循重定向(它使用默认的蜘蛛来获取数据)。如果我正在运行我的蜘蛛,它会遵循 301 - 但我无法调试。
如何让 shell 跟随 301 以允许调试最终页面?
最佳答案
Scrapy 使用重定向中间件进行重定向,但它在 shell 中未启用。对此的快速修复:
scrapy shell "https://jigsaw.w3.org/HTTP/300/301.html"
fetch(response.headers['Location'])
此外,为了调试您的蜘蛛,您可能需要检查您的蜘蛛收到的响应:
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
关于python - Scrapy - shell 中的 301 重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38683382/