scrapy pymongo設定密碼

2021-10-03 11:59:54 字數 1111 閱讀 4647

在settings.py檔案中新增資料庫的配置項

mongo_host =

"127.0.0.1"

# 主機ip

mongo_port = 27017 # 埠號

mongo_db =

"spider"

# 庫名

mongo_coll =

"heartsong"

# collection名

# mongo_user = "zhangsan"

# mongo_psw = "123456"

然後編寫pipelines.py

coding: utf-8 -*-

import pymongo

from scrapy.conf import settings

class heartsongpipeline(object):

def __init__(self):

# 鏈結資料庫

self.client = pymongo.mongoclient(host=settings[

'mongo_host'

], port=settings[

'mongo_port'])

# 資料庫登入需要帳號密碼的話

# self.client.admin.authenticate(settings['mingo_user'], settings['mongo_psw'])

self.db = self.client[settings[

'mongo_db']]

# 獲得資料庫的控制代碼

self.coll = self.db[settings[

'mongo_coll']]

# 獲得collection的控制代碼

def process_item(self, item, spider):

postitem = dict(item)

# 把item轉化成字典形式

self.coll.insert(postitem)

# 向資料庫插入一條記錄

return item # 會在控制台輸出原item資料,可以選擇不寫

摘自於

儲存設定 設定 CATIA自動儲存設定

問題 在使用catia設計時,大約每隔半小時就會遇到一次 卡死 特別是設計任務較為複雜時,卡死 的時間會較長,此時我們只好暫停設計工作,等待恢復 多數情況下 這是catia在自動儲存時的 卡滯 而不是真正的 卡死 目的就是防止沒有主動儲存習慣的小夥伴,遇見 意外情況 真正 卡死 後,重啟catia還...

pycharm 常用設定設定

1.自動加冒號 換行 complete current statement ctrl shift enter 與虛擬機器衝突 修改為 ctrl shift 2.儲存成模板 ctrl shift l live template 3.設定 pycharm 注釋字型顏色 setting font lang...

linux centos ip設定網絡卡設定

1 自動獲取ip位址 虛擬機器使用橋接模式,相當於連線到物理機的網路裡,物理機網路有dhcp伺服器自動分配ip位址。dhclient 自動獲取ip位址命令 ifconfig 查詢系統裡網絡卡資訊,ip位址 mac位址 分配到ip位址後,用物理機進行ping ip位址,檢測是否ping通。2 手動設定...