如何通过Python下载此GIF(动态)? [英] How to download this GIF(dynamic) by Python?
本文介绍了如何通过Python下载此GIF(动态)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我以一个网址为例:
http://ww4.sinaimg.cn/large/a7bf601fjw1f7jsbj34a1g20kc0bdnph.gif
您可以在浏览器中看到它.
You can see it in your browser.
现在我要下载它.我尝试过:
1.
urllib.urlretrieve(imgurl,filepath')
失败,出现错误"图片.
failed, got an "error" picture.
2.
wget.download(imgurl)
失败,出现错误"图片.
failed, got an "error" picture.
3.
r = requests.get(imgurl,stream=True)
img = PIL.Image.open(StringIO(r.content))
img.save(filepath)
r = requests.get(imgurl,stream=True)
img = PIL.Image.open(StringIO(r.content))
img.save(filepath)
失败,得到一张静态图片,我的意思是,只有一帧.
failed, got a static picture, I mean, just one frame.
那我该怎么办?
推荐答案
这对我来说效果很好,可以获取动画gif:
This works quite fine for me, to get the animated gif:
>>> import requests
>>> uri = 'http://ww4.sinaimg.cn/large/a7bf601fjw1f7jsbj34a1g20kc0bdnph.gif'
>>> with open('/tmp/pr0n.gif', 'wb') as f:
... f.write(requests.get(uri).content)
...
开心的碰碰!
这篇关于如何通过Python下载此GIF(动态)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文