我正在瀏覽一組頁面,我不確定有多少頁面,但當前頁面是由URL中存在的簡單數字表示的(例如「http://www.website.com/page/1」 )檢查網址是否有404錯誤scrapy
我想在scrapy中使用for循環來增加頁面上的當前猜測,並在達到404時停止。我知道從請求返回的響應包含此信息,但我不是確定如何自動從請求中獲得響應。
有關如何做到這一點的任何想法?
目前我的代碼是沿着線的東西:
def start_requests(self):
baseUrl = "http://website.com/page/"
currentPage = 0
stillExists = True
while(stillExists):
currentUrl = baseUrl + str(currentPage)
test = Request(currentUrl)
if test.response.status != 404: #This is what I'm not sure of
yield test
currentPage += 1
else:
stillExists = False
根據我的經驗,大多數自定義404頁確實會返回404狀態碼。 – Taymon 2013-04-08 02:11:09
原來,他們沒有,我不能真正解決這個問題,沒有檢查他們的內容,這太慢了,但這個答案通常會解決問題。 – 2013-04-08 03:38:00