美文网首页
网络爬虫:使用pymysql进行数据库交互

网络爬虫:使用pymysql进行数据库交互

作者: 牛耀 | 来源:发表于2018-12-23 14:41 被阅读0次
import pymysql
 mysql_client =pymysql.Connect('127.0.0.1','root','18603503110','1712B',3306,charset='utf8')
    # 创建游标(执行mysql语句)
    cursor = mysql_client.cursor()
sql = """
    INSERT INTO ...(%s)
    VALUE (%s)
    """%(','.join(dict.keys()),','.join(['%s']*len(dict)))
    try:
        cursor.execute(sql,list(dict.values()))
        mysql_client.commit()
    except Exception as err:
        print(err)
        mysql_client.rollback()

相关文章

网友评论

      本文标题:网络爬虫:使用pymysql进行数据库交互

      本文链接:https://www.haomeiwen.com/subject/jklnkqtx.html