import requests
import time
import os
def download_img():
url = 'http://pic.58pic.com/58pic/16/42/96/56e58PICAu9_1024.jpg'
print('开始下载图片')
t1 = time.time()
response = requests.get(url,stream = True)
with open(os.path.abspath('build/demo.jpg'),'wb') as img:
for tmp in response.iter_content(128):
img.write(tmp)
print('下载完成耗时:%s,文件路径:%s'%(time.time()-t1,os.path.abspath('build/demo.jpg')))
复制代码
转载于:https://juejin.im/post/5a3110dd6fb9a044ff3175e5