目前在Amazon data scraper中使用Scrapy进行分页,我使用
next_page = response.xpath('//li[@class="a-last"]/a/@href').get()
if next_page:
next_page = 'https://www.amazon.com' + next_page
yield scrapy.Request(url=next_page,callback=self.parse,headers=self.amazon_header,dont_filter=True)
如果我只想从前3页获取数据,我该怎么做?
进入settings.py文件,按如下方式限制分页:
CLOSESPIDER_PAGECOUNT = 3
选择:假设,Url =['https://www.quote.toscrape/page=1 something']
现在在start_urls中以这种方式进行分页,并排除next分页
start_urls =[ 'https:// www.quote.toscrape/page='+str(x)+' something' for x in range(1,3)]