# -*- coding: utf-8 -*-

# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://docs.scrapy.org/en/latest/topics/item-pipeline.html
import pymysql class QuotesPipeline(object): def __init__(self):
self.conn = pymysql.connect(host='xxxxxxx', user='root', passwd='xxxxxxx', db='spider', charset='utf8')
self.cur = self.conn.cursor() def open_spider(self,spider):
print('spider start') def process_item(self, item, spider): try:
import time
# 格式化成2016-03-20 11:45:39形式
now = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
sql = "insert ignore into test(author,content,created_at) values('{}','{}','{}')".format(item['author'],item['content'],now)
reCount = self.cur.execute(sql)
self.conn.commit()
except Exception as e:
print(str(e)) return item

pip install pymsql

最新文章

  1. 如何在Linux服务器中隐藏PHP版本
  2. CSS3之3D变换实例详解
  3. android开源项目和框架
  4. [LeetCode]题解(python):091 Decode Ways
  5. hdu 2426 Interesting Housing Problem 最大权匹配KM算法
  6. 【UML】——为什么要使用UML
  7. 关于oracle的函数,存储过程,触发器,序列,视图,左右连接一些的应用 带案例
  8. PID204 / 特种部队
  9. CentOS 6使用VNC配置远程桌面
  10. C#单元测试工具包:MvcContrib
  11. SQL注入(三)
  12. 在用python操作mysql时报错:ModuleNotFoundError: No module named 'MySQLdb'
  13. ArcGIS 网络分析[2.1] 最短路径
  14. java垃圾回收GC
  15. Django--缓存设置
  16. pascal与其它语言代码书写的不同和pascal的快捷键
  17. 20.pipe
  18. C#计算机性能参数
  19. CVE-2010-2553 Microsoft Windows Cinepak 编码解码器解压缩漏洞 分析
  20. Oracle查询一个表的数据插入到另一个表

热门文章

  1. 程序员你是如何降低NPE的?
  2. sql分页存储过程,带求和、排序
  3. (专题四)05 matlab视角处理
  4. apisix网关-构建docker镜像构建及插件化开发
  5. top、ps -ef、ps aux的区别及内容详解
  6. Java中toCharArray()方法
  7. 【JAVA】JAVA相关知识点收集
  8. (最新 9000 字 )Spring Boot 配置特性解析
  9. 阿里内部推出Spring响应式微服务Boot2Cloud文档
  10. 手把手教你springboot中导出数据到excel中