class MySQLPipeline(object):
def __init__(self):
# 连接数据库
self.connect = pymysql.connect(
host='xxx.xxx.x.xxx', # 数据库地址
port=3306, # 数据库端口
db='mysql', # 数据库名
user='root', # 数据库用户名
passwd='xxxxxxx', # 数据库密码
charset='utf8', # 编码方式
use_unicode=True)
# 通过cursor执行增删查改
self.cursor = self.connect.cursor()
def process_item(self, item, spider):
self.cursor.execute(
"""insert into test(A ,B,C,D,E,F,G,H,I,J,K,L,M) # 使用%s格式化字段值
value (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)""",
(
item['A'],
item['B'],
item['C'],
item['D'],
item['E'],
item[&#
Python Scrapy 框架连接mysql数据库
最新推荐文章于 2023-04-07 16:01:23 发布