编辑: 答:我需要为“einlesen()”函数创建另一个游标。在
这是我第一次在Python中使用SQLite3,请原谅我(可能)糟糕的语法;) 我试图建立一个DVD数据库,直接从amazon获取必要的信息(演员等)。整个程序基于SQLite3和python2.7。在
一切都很好,除了我的plannes“更新”功能。在
def update():
print 'Update Datenbank....bitte warten....'
cursor.execute('''SELECT titel, amazon, erhalten, ausgeliehen FROM movies''')
antwort = 'update'
for row in cursor:
stelle = row[1]
ausg = row[2]
erh = row[3]
einlesen(stelle, ausg, erh, antwort)
print row[0]
raw_input('Update komplett!')
menu()
问题是,循环在一次迭代后退出。在
输出如下:
^{pr2}$所以我知道,循环和函数调用是正确的(数据库得到正确的更新-由函数'einlesen()'完成),但是还有更多的迭代,而不仅仅是一个。。。 所以我的问题是:怎么了?;)
以下是(缩写)“einlesen()”函数:
def einlesen(asin, ausg, erh, antwort):
d = {}
infos = urllib.urlopen('http://www.amazon.de/dp/'+asin).read()
titel = infos[infos.find('Kaufen Sie')+11:infos.find('nstig ein')-3]
art = 'dvd'
infos = remove_html_tags(infos)
infos = infos[infos.find('Darsteller: '):infos.find('Durchschnittliche')]
infos = infos.split('\n')
for x in range(200):
try:
infos.remove('')
except:
break
for element in infos:
d[element.split(': ')[0].lstrip()] = element.split(': ')[1]
#(excluded the whole Info-Scraping process)
if antwort == 'update':
movie = dauer, art, regie, jahr, fsk, darsteller, titel
sql = ('''UPDATE movies SET laufzeit = ?, art = ?, regie = ?, jahr = ?, fsk = ?, darsteller = ? WHERE titel = ?''')
cursor.execute(sql, movie)
connection.commit()
else:
menu()
谢谢你的帮助。在
当您仍在循环
SELECT
的结果时执行UPDATE
。这将删除第一个cursor.execute()
的结果。在使用第二个光标。在
编辑:
相关问题 更多 >
编程相关推荐