# -*- 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. 使用nodejs爬取拉勾苏州和上海的.NET职位信息
  2. Python之路 day2 文件基础操作
  3. 在VS中添加lib的简单方法
  4. KeepAlived主备模型高可用LVS
  5. 动态加载HTML后使用query修改标签样式
  6. kafka 生产者java编码
  7. iOS开发中常用第三方库的使用和配置-GDataXML
  8. :Hibernate逍遥游记-第16管理session和实现对话
  9. 【Cocos2d-X开发学习笔记】第09期:渲染框架之菜单类(CCMenu)的使用
  10. HTTP协议学习-02
  11. 常用颜色RGB、灰度值
  12. 一键安装Cloud Torrent
  13. Python2 编码问题分析
  14. latex 一些使用
  15. Apache Hadoop学习笔记一
  16. SQL 经典应用
  17. google的python语言规范
  18. JavaWeb学习 (十八)————JSP标签
  19. January 20th, 2018 Week 3rd Saturday
  20. Python--Redis实战:第四章:数据安全与性能保障:第7节:非事务型流水线

热门文章

  1. CentOS7下NFS服务安装及配置固定端口
  2. BATJ都爱问的多线程面试题
  3. Hive学习笔记——metadata
  4. 工控随笔_24_关于西门子Step7的Simatic manager打开报3280:503错误。
  5. Mac Pro 2015休眠掉电解决办法
  6. FLINK-11738
  7. PHP防止刷微信红包方法
  8. 《ucore lab1 exercise4》实验报告
  9. Fineui 实现点击左边树状主菜单链接 打开新窗口或打开多个同一个tab
  10. 'cross-env' 不是内部或外部命令,也不是可运行的程序 或批处理文件。 npm ERR! code ELIFECYCLE npm ERR! errno 1