我有一些代码,可以通过API获取《纽约时报》文章的元数据。有些链接是redirects \ timed链接,我需要指向article的真正链接。该链接不应该转到sqlite数据库。这是我尝试过的:
查看代码
if r.history:
print ("Request was redirected")
for resp in r.history:
print (resp.status_code, resp.url)
funktioniert nicht --> bricht per fehler ab
redirect = str(resp.url)
Redirect_url_exists = False
try:
if database.execute('SELECT COUNT(*) FROM nyt WHERE redirect = ?', (redirect,)).fetchone()[0] > 0:
Redirect_url_exists = True
break
except:
pass
if Redirect_url_exists:
continue
print ("Final destination:")
print (response.status_code, response.url)
else:
print ("Request was not redirected")
print(r.headers)
没有写下错误...但是当我全部跳过时,它又可以工作了。