从零开始学网络爬虫之数据区MySQL

来源:互联网 发布:二叉树反转 java 编辑:程序博客网 时间:2024/04/19 05:03
import MySQLdbconn=MySQLdb.Connect(host='localhost',user='root',passwd='')cursor =conn.cursor()cursor.execute('create database if not exists student')#conn.commit()conn.select_db('student')cursor =conn.cursor()sql = "create table if not exists test1(name varchar(128), age int(4))" #cursor.execute(sql)##cursor =conn.cursor()sql = "insert into test1(name, age) values ('%s', %d)" % ("zhaowei", 23)try:    cursor.execute(sql)except Exception, e:    print e 

0 0