在我的蜘蛛中,我有一些这样的代码:
next_page_url = response.follow(
url=self.start_urls[0][:-1]+str(page_number+1),callback=self.next_page
)
if next_page_url:
next_page看起来像这样:
def next_page(self,response):
next_page_count = len(<xpath I use>)
if next_page_count > 0:
return True
else:
return False
在继续下一段代码之前,需要设置next_page_url。 这段代码实质上是出于某些文件写入目的检查当前页面是否为最后一页