[Python] [爬蟲] 11.批量政府網站的招投標、中標資訊爬取和推送的自動化爬蟲——日誌監控
阿新 • • 發佈:2018-12-20
目錄
1.Intro
檔名:log_record.py
模組名:日誌監控
引用庫:
pymongo |
功能:爬蟲執行結果寫入到資料庫的日誌表中,便於檢視每天執行情況,執行失敗時再追溯日誌。
2.Source
#!/usr/bin/env python # -*- coding: utf-8 -*- ''' # Author : YSW # Time : 2018/10/8 11:41 # File : log_record.py # Version : 1.0 # Describe: 日誌監控模組 # Update : ''' import pymongo # 本地 mongodb 引數 username = "localhost" port = 27017 # 連線 mongodb client = pymongo.MongoClient(username, port) # 建立資料庫 logDB = client['Log_DB'] # 建立資料表,用於儲存日誌資訊 logTable = logDB['log_execute'] def log_recorder(current_time, execute_result): log_data = { "執行時間": current_time, "執行結果": execute_result } logTable.insert_one(log_data)