想要对一个页面进行监控,这个页面是有分页,目前实现了所有分页的抓取,那么想要回到第一个分页来监控,请问怎么写。
if len(response.css('li.next.disabled a::attr(href)').extract()) == 0:
next_page = response.css('li.next a::attr(href)')[0].extract()
next_page = response.urljoin(next_page)
yield scrapy.Request(next_page, callback=self.parse)
else:
yield scrapy.Request(self.start_urls[0], callback=self.parse)
上面的代码会报错:
- no more duplicates will be shown (see DUPEFILTER_DEBUG to show all duplicates)
如何使出现异常仍然可以继续进行呢?
谢谢
使用try语句