这很奇怪(不过,这是我第一次尝试使用python/sqlite),但是如果我执行fetchAll(),我似乎可以获得所有行,但除此之外 - 无论我尝试什么,总是会结束在db中只返回第一行 - 第二次迭代因为返回null而停止.想知道我是如何在python中编写代码的?db好像..
con = sqlite3.connect('backup.db')
con.row_factory = sqlite3.Row
cur = con.cursor()
cur.execute('select * from tb1;')
for row in cur:
try:
# row = dataCur.fetchone()
#if row == None: break
print type(row)
print ' Starting on: %i' % row[0]
cleaner = Cleaner(scripts=True, remove_tags=['img'], embedded=True)
try:
cleaned = cleaner.clean_html(row[2]) #data stored in second col
cur.execute('update tb1 set data = ? where id = ?;', (cleaned, row[0]))
except AttributeError:
print 'Attribute error'
print ' Ended on: %i' % row[0]
except IOError:
print 'IOexception'
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
861 次 |
| 最近记录: |