【发布时间】:2014-11-09 18:52:09
【问题描述】:
我想知道是否有人可以帮助我弄清楚为什么我的 python 脚本收集的数据没有正确输入到 mysql 数据库中
这是我的代码
/*** index is a dictionary that has the struture:
index = {links:[words], links: [words],.......} ***/
#There are multiple items in words
for k, v in index.iteritems():
links = str(k)
words = str(v) [1:-1]
import MySQLdb
db = MySQLdb.connect("localhost","root","","my_db" )
cursor = db.cursor()
try:
cursor.execute(('insert into SITE(url, keywords) values("%s", "%s")' % \
(links,words)))
db.commit()
except:
db.rollback()
db.close()
我表中的每一行都应该有两个字段:url 和关键字 它只插入两行,而不是插入 6 行。 请帮忙?!
【问题讨论】:
-
请显示“索引”的内容