python爬蟲的資料庫連線問題 推薦

2022-09-27 11:42:10 字數 733 閱讀 3733

1.需要導的包

import pymysql

2.# mysql連線資訊(字典形式)

db_config =

3.# 獲得資料庫連線

connection = pymysql.connect(**db_config)

connection()具體的基礎知識詳見程式設計客棧連線

4.具體連線(以簡書為例)

try:

# 獲得資料庫游標(游標提供了一種對從表中檢索出的資料進行操作的靈活手段,就本質而言,游標實際上是一種能從包括多條資料記錄的結果集中每次提取一條記錄的機制。游標總是與一條sql 選擇語句相關聯因為游標由結果集(可以是零條、一條或由相關的選擇語句檢索出的多條記錄)和結果集中指向特定記錄的游標位置組成。)

with connection.cursor() as cursor:

sql = 'insert into ******book(title, url) values(%s, %s)'

for u in urls:

# 執行sql語句

# 事務提交

connection.commit()

finally:

# 關閉資料庫連線

connection.close()

5.連線資料庫成功,並得到資料

總結本文位址:

python爬蟲 連線資料庫2

連線mongodb.可以在c盤建立2個資料夾。c data db,和c data log。在log目錄下新建乙個檔案,日誌檔案,mongodb.log mongodb資料庫檔案設定。執行 cdm.exe 開啟mongodb所在的安裝目錄,mongodb server 3.4 bin,輸入mongod...

python 資料庫 爬蟲

python3 和 pip3 安裝 安裝 selenium 配置驅動的環境變數,或者將驅動放到已經配置好的資料夾中,類似 window 的 cmd的目錄 window c windows system32 linux usr bin usr local bin 安裝 pyquery 安裝pymysq...

powerdesigner連線資料庫的問題

1.jvm不能初始化 要求安裝32位的jdk,把path指向32的安裝目錄 2.non sql error could not load class oracle.jdbc.oracledriver 把odbc14.jar包放到powerdesigner安裝目錄,後加入classpath 3.non...