然后把爬虫爬到的bai数据通过mysql里面的insert语句查到du数据库,当然也可以zhi建表dao,一般我没用python建表 是先建好再写数据的
import mysql.connector
conn = mysql.connector.connect(
user='root',
password='root',
host='127.0.0.1',
port='3306',
database='test_demo'
)
cursor = conn.cursor()
cursor.execute("INSERT INTO test_user(`uuid`,`user_name`,`user_level`) VALUES (%s,%s,%s)",[id, user_name, user_level])
cursor.execute("INSERT INTO tieba_user_detail(`user_name`,`user_exp`,`user_sex`,`tieba_age`,`tieba_note`,`user_favorites`,`user_fans`) VALUES (%s,%s,%s,%s,%s,%s,%s)",[user_name,user_exp,user_sex, tieba_age,tieba_note, user_favorites, user_fans])
print('************** %s %s 数据保存成功 **************'%(user_rank,user_name))
conn.commit()
cursor.close()
简单的方法是:variable_1 = "HELLO"
variable_2 = "WORLD"
varlist = [variable_1, variable_2]
print "INSERT INTO table VALUES %r" % (tuple(varlist),)
关键是把list转换成tuple
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)