鍍金池/ 問答/人工智能  HTML5  Python/ Scrapy循環(huán)爬取

Scrapy循環(huán)爬取

想要對(duì)一個(gè)頁面進(jìn)行監(jiān)控,這個(gè)頁面是有分頁,目前實(shí)現(xiàn)了所有分頁的抓取,那么想要回到第一個(gè)分頁來監(jiān)控,請(qǐng)問怎么寫。

        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)

上面的代碼會(huì)報(bào)錯(cuò):

  • no more duplicates will be shown (see DUPEFILTER_DEBUG to show all duplicates)

如何使出現(xiàn)異常仍然可以繼續(xù)進(jìn)行呢?
謝謝

回答
編輯回答
影魅

try:

except...

2018年3月19日 20:02
編輯回答
不歸路

使用try語句

2017年8月13日 09:31
編輯回答
若相惜

使用try語句捕獲異常

try:
   ...
except Exception, err:
   pass
2018年5月2日 10:59