This question already has an answer here:
这个问题在这里已有答案:
- How to download image using requests 10 answers
- 如何使用请求10个答案下载图像
I give an url as example:
我给一个网址作为例子:
http://ww4.sinaimg.cn/large/a7bf601fjw1f7jsbj34a1g20kc0bdnph.gif
You can see it in your browser.
您可以在浏览器中看到它。
Now I want to download it. I have tried:
现在我想下载它。我努力了:
1.
1。
urllib.urlretrieve(imgurl,filepath')
urllib.urlretrieve(imgUrl的,文件路径')
failed, got an "error" picture.
失败了,得到了一个“错误”的图片。
2.
2。
wget.download(imgurl)
wget.download(imgUrl的)
failed, got an "error" picture.
失败了,得到了一个“错误”的图片。
3.
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.
失败了,得到一张静态图片,我的意思是,只有一帧。
So what should I do?
所以我该怎么做?
1 个解决方案
#1
6
This works quite fine for me, to get the animated gif:
这对我来说非常好,以获得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)
...
Happy fapping!
快乐的捣蛋!
#1
6
This works quite fine for me, to get the animated gif:
这对我来说非常好,以获得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)
...
Happy fapping!
快乐的捣蛋!