|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
def __download_and_save_image(link, directory, src='fotolia'):
print("Attempting to download: " + link)
r = requests.get(link)
if r.status_code == 200:
# depends on source
if src == 'fotolia':
try:
filename = r.headers['Content-Disposition'].split('filename="')[1][:-2]
except:
print("No Content-Disposition header present.")
return
elif src == 'istock':
try:
filename = r.headers['Content-Disposition'].split('filename=')[1]
except:
print("No Content-Disposition header present.")
return
filename = os.sep.join([directory, filename])
print("Saving to filename: %s "%(filename))
with open(filename, 'wb') as f: f.write(r.content)
else : print("Couldn't download from link: " + link)
|
|