鍍金池/ 教程/ Python/ 異常(Exceptions)
Benchmarking
命令行工具(Command line tools)
下載器中間件(Downloader Middleware)
信號(hào)(Signals)
Telnet 終端(Telnet Console)
初窺 Scrapy
數(shù)據(jù)收集(Stats Collection)
Scrapyd
通用爬蟲(chóng)(Broad Crawls)
Item Loaders
試驗(yàn)階段特性
Scrapy 入門(mén)教程
自動(dòng)限速(AutoThrottle)擴(kuò)展
Settings
Scrapy 終端(Scrapy shell)
下載項(xiàng)目圖片
DjangoItem
調(diào)試(Debugging)Spiders
選擇器(Selectors)
Feed exports
Spiders Contracts
借助 Firefox 來(lái)爬取
Logging
Spiders
Ubuntu 軟件包
實(shí)踐經(jīng)驗(yàn)(Common Practices)
安裝指南
Item Exporters
擴(kuò)展(Extensions)
Items
Spider 中間件(Middleware)
異常(Exceptions)
例子
發(fā)送 email
架構(gòu)概覽
常見(jiàn)問(wèn)題(FAQ)
Jobs:暫停,恢復(fù)爬蟲(chóng)
核心 API
使用 Firebug 進(jìn)行爬取
Item Pipeline
Link Extractors
Web Service
調(diào)試內(nèi)存溢出

異常(Exceptions)

內(nèi)置異常參考手冊(cè)(Built-in Exceptions reference)

下面是 Scrapy 提供的異常及其用法。

DropItem

exception scrapy.exceptions.DropItem

該異常由 item pipeline 拋出,用于停止處理 item。詳細(xì)內(nèi)容請(qǐng)參考 Item Pipeline。

CloseSpider

exception scrapy.exceptions.CloseSpider(reason='cancelled')

該異常由 spider 的回調(diào)函數(shù)(callback)拋出,來(lái)暫停/停止 spider。支持的參數(shù):

參數(shù):

  • reason (str) – 關(guān)閉的原因

樣例:

def parse_page(self, response):
    if 'Bandwidth exceeded' in response.body:
        raise CloseSpider('bandwidth_exceeded')

IgnoreRequest

exception scrapy.exceptions.IgnoreRequest

該異常由調(diào)度器(Scheduler)或其他下載中間件拋出,聲明忽略該 request。

NotConfigured

exception scrapy.exceptions.NotConfigured

該異常由某些組件拋出,聲明其仍然保持關(guān)閉。這些組件包括:

  • Extensions
  • Item pipelines
  • Downloader middlwares
  • Spider middlewares

該異常必須由組件的構(gòu)造器(constructor)拋出。

NotSupported

exception scrapy.exceptions.NotSupported

該異常聲明一個(gè)不支持的特性。

上一篇:安裝指南下一篇:Feed exports