爬虫框架存储pymysql方式

爬虫框架存储pymysql方式
# -*- coding: utf-8 -*-
import pymysql
# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://doc.scrapy.org/en/latest/topics/item-pipeline.html
db = pymysql.connect(user='root',password='root',port=3306,db='233',charset='utf8')
cursor = db.cursor()
class YaowenPipeline(object):
def process_item(self, item, spider):
title = item['title']
create_time = item['create_time']
author = item['author']
keyword = item['keyword']
source = item['source']
types = item['types']
desc = item['desc']
sql = 'insert into yaowen(title,create_time,author,keyword,source,types,`desc`) VALUES ("{}","{}","{}","{}","{}","{}","{}")'.format(title,create_time,author,keyword,source,types,desc)
print(sql)
cursor.execute(sql)
db.commit()
return item

原文地址:https://www.cnblogs.com/duanlinxiao/p/9820689.html