Scrapy循环爬取

想要对一个页面进行监控,这个页面是有分页,目前实现了所有分页的抓取,那么想要回到第一个分页来监控,请问怎么写。

        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)

如何使出现异常仍然可以继续进行呢?
谢谢

阅读 4.8k
3 个回答
新手上路,请多包涵

try:

except...

使用try语句捕获异常

try:
   ...
except Exception, err:
   pass
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题