zoukankan      html  css  js  c++  java
  • 爬虫框架存储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

  • 相关阅读:
    Teradata 奇淫技巧
    Java
    搬砖
    js 判断2个对象的值是否相等
    搬砖
    UnsupportedClassVersionError: JVMCFRE003 commons/text/StringEscapeUtils
    杂记
    java查找最新文件
    搬砖
    搬砖
  • 原文地址:https://www.cnblogs.com/duanlinxiao/p/9820689.html
Copyright © 2011-2022 走看看