Ben*_*eni 1 python-3.x python-requests
我无法从JavaScript生成的图像下载并将其存储在本地计算机上。下面的代码没有给出任何错误,但是我的文件夹中没有图像。我已经尝试了很多方法。这是其中之一:
path = "http://my.site.com/page/oo?_b=9V2FG34519CV2N56SLK567943N25J82V"
os.makedirs('C:/Images', exist_ok=True)
print('Dowload images %s...' % path)
res = request.get(path)
res.raise_for_status()
imageFile = open(os.path.join('logos', os.path.basename(res)), 'wb')
for chunk in res.iter_content(100000):
imageFile.write(chunk)
imageFile.close()
Run Code Online (Sandbox Code Playgroud)
我自两天以来一直在努力解决此问题,因此,如果有人可以帮助我,我将不胜感激!
获得图像后url,就可以使用requests和shutil将图像保存到给定目录(对于给定的目录适用于我url):
import shutil
import requests
import os
url = 'http://epub.hpo.hu/e-kutatas/aa?_p=A554F6BCDBCEA51EFF1E0E17E777F3AC'
response = requests.get(url, stream=True)
with open(out_file_path, 'wb') as out_file:
shutil.copyfileobj(response.raw, out_file)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2382 次 |
| 最近记录: |