【发布时间】:2013-03-29 17:43:44
【问题描述】:
我正在浏览一组页面,我不确定有多少,但当前页面由 url 中的一个简单数字表示(例如“http://www.website.com/page/1”)
我想在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
【问题讨论】:
标签: python web-scraping http-status-code-404 scrapy