html python 数据库_如何在数据库中存储HTML(SQLITE PYTHON)

这可能很简单,但我到不了那里。。。在

如何在SQLITE数据库中存储html代码?在

我使用文本作为数据库中字段的数据类型(应该是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.

另外,我更希望它是文本(人类可读)而不是blob,但如果这是更简单的方式,我完全赞成。在

塔克斯

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值