首页 > 数据库技术 > 详细

爬取的地址存入mysql记录

时间:2019-11-22 11:35:28      阅读:86      评论:0      收藏:0      [点我收藏+]
CREATE DATABASE HELLO;

CREATE TABLE IF NOT EXISTS `botoo`(
   `id` INT UNSIGNED AUTO_INCREMENT,
   `title` VARCHAR(100),
   `url` VARCHAR(100) ,
   `downloadUrl` VARCHAR(100) NOT NULL unique,
   `releaseTime` DATE,
   `state`  int(11) DEFAULT 1 , 
   `insertTime` DATE,
   PRIMARY KEY ( `id` )
)ENGINE=InnoDB DEFAULT CHARSET=utf8;



insert into botoo (title,url,downloadUrl,releaseTime,insertTime)  values(测试,http://www.baidu.com,www.baidu.com,2019-11-22 10:00:00,2019-11-22 10:00:01);

 

 

 

import pymysql.cursors
import time 


def localTime():

    now = int(time.time()) 
    timeStruct = time.localtime(now) 
    strTime = time.strftime("%Y-%m-%d %H:%M:%S", timeStruct) 
    return strTime


def insertSqlLanguage(title,url,downloadUrl,releaseTime):
    insertDate = f"(‘{title}‘,‘{url}‘,‘{downloadUrl}‘,‘{releaseTime}‘,‘{localTime()}‘)"
    sqlLanguage = f"insert into sesese (title,url,downloadUrl,releaseTime,insertTime) values {insertDate}"
    return sqlLanguage


if __name__ == __main__:

    connect= pymysql.Connect(    
            host=xxxxxxxx,
            user=xxxxx,
            password=xxxxxx,
            port=3306,
            db=xxxxxxxx,
            charset=utf8)
    cursor = connect.cursor()
    insertSql = insertSqlLanguage(测试,http://www.baidu.com,www.baidu.com,2019-11-22 10:00:00)

    cursor.execute(insertSql)
    connect.commit()

 

爬取的地址存入mysql记录

原文:https://www.cnblogs.com/botoo/p/11910459.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!