scrapy框架【log日誌】

scrapy框架之log日誌

 

scrapy中的debug信息

在scrapy中設置log

一、在settings中設置log級別,在settings.py中添加一行:html

複製代碼
Scrapy提供5層logging級別:

CRITICAL - 嚴重錯誤(critical)

ERROR - 通常錯誤(regular errors)

WARNING - 警告信息(warning messages)

INFO - 通常信息(informational messages)

DEBUG - 調試信息(debugging messages)
複製代碼

scrapy默認顯示DEBUG級別的log信息app

二、將輸出的結果保存爲log日誌,在settings.py中添加路徑:框架

LOG_FILE = './log.log'

三、顯示log位置,在pipelines.py中:dom

複製代碼
import logging

logger = logging.getLogger(__name__)

def process_item(self, item, spider):
    logger.warning(item)
    ....
複製代碼

4.在spider文件中引入Log日誌:scrapy

複製代碼
class DcdappSpider(scrapy.Spider):
    name = 'dcdapp'
    allowed_domains = ['m.dcdapp.com']
    custom_settings = {
        # 設置管道下載
        'ITEM_PIPELINES': {
            'autospider.pipelines.DcdAppPipeline': 300,
        },
        # 設置log日誌
        'LOG_LEVEL':'DEBUG',
        'LOG_FILE':'./././Log/dcdapp_log.log'
    }
複製代碼
相關文章
相關標籤/搜索