2016-07-31 77 views
2

我無法找到以下問題的解決方案。我正在使用Scrapy(最新版本),並試圖調試蜘蛛。 使用scrapy shell https://jigsaw.w3.org/HTTP/300/301.html - >它不遵循重定向(它使用默認的蜘蛛來獲取數據)。如果我正在運行我的蜘蛛,它會遵循301 - 但我無法調試。Scrapy - 301在shell中重定向

如何讓shell遵循301以允許調試最終頁面?

回答

8

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 
+0

的感謝!這似乎是一個快速解決方案,讓我可以繼續! – Pixelartist

+0

@Pixelartist沒問題,請參閱我的編輯瞭解更多關於正確調試蜘蛛的信息。 – Granitosaurus

+0

我認爲額外的編輯是一種完整的解決方案。我希望你可以配置shell的行爲,但是這個 - 它解決了它。 – Pixelartist