scrapy怎么連接mysql?
settings = get_project_settings()
# 獲取settings文件中的配置
dbparms=dict(
host=settings['MYSQL_HOST'], #讀取settings中的配置
db=settings['MYSQL_DBNAME'],
user=settings['MYSQL_USER'],
passwd=settings['MYSQL_PASSWD'],
charset='utf8', #編碼要加上,否則可能出現中文亂碼問題
cursorclass=pymysql.cursors.DictCursor,
use_unicode=False,
)
# 使用Twisted中的adbapi獲取數據庫連接池對象
dbpool = adbapi.ConnectionPool("pymysql", **dbparms)