Sprawdzanie adresu URL w celu usunięcia błędu 404
Przeglądam zestaw stron i nie jestem pewien, ile ich jest, ale bieżąca strona jest reprezentowana przez prosty numer obecny w adresie URL (np. „http://www.website.com/page/1„)
Chciałbym użyć pętli for w scrapy, aby zwiększyć bieżące przypuszczenie na stronie i zatrzymać, gdy osiągnie 404. Wiem, że odpowiedź, która jest zwracana z żądania, zawiera te informacje, ale nie jestem pewien, jak automatycznie uzyskać odpowiedź z prośby.
Jakieś pomysły, jak to zrobić?
Obecnie mój kod jest czymś w rodzaju:
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