这可能是很简单,但我不能让那里...我如何保存HTML在DB(SQLITE PYTHON)
我如何可以存储HTML代码在一个SQLite数据库?
我用文字作为DB数据类型的字段(它应该是BLOB?)
我得到奇怪的错误(和相同的输入误差修改变化,所以我觉得它是与转义)
我的代码:
con = sqlite.connect(bd)
cur = con.cursor()
temp=cur.execute ('SELECT * from posts').fetchall()
#temp[Z][1] = ID
#temp[Z][4] = URL
i=0
while i< len (temp):
if temp[i][0]==None:
try:
html = urllib2.urlopen(str(temp[i][4])).read()
except:
html=None
#sql = 'UPDATE posts SET html = "' + str(html) + '" WHERE id = ' + str(temp[i][1])
#cur.execute('UPDATE posts SET html = ? WHERE id = ?' ,(html,temp[i][1]))
cur.execute("UPDATE posts SET html = '" + str(html) + "' WHERE id = " + str(temp[i][1]))
con.commit()
print temp[i][4]
i=i+1
的错误:
1 -
OperationalError: near "2": syntax error WARNING: Failure executing file: Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56) Type "copyright", "credits" or "license" for more information.
2-
ProgrammingError: You must not use 8-bit bytestrings unless you use a text_factory that can interpret 8-bit bytestrings (like text_factory = str). It is highly recommended that you instead just switch your application to Unicode strings.
P.S.我宁愿如果它是文本(人类可读)比blob,但如果它是更简单的方式,我都是为了它。
感谢名单
100%正确。 Namaste我的朋友或我向你鞠躬。谢谢 – 2010-12-18 21:48:23