-2

I give an url as example:

imgurl = "http://ww4.sinaimg.cn/large/a7bf601fjw1f7jsbj34a1g20kc0bdnph.gif"

You can see it in your browser.

Now I want to download it. I have tried:

urllib.urlretrieve(imgurl, filepath)

failed, got an "error" picture.

wget.download(imgurl)

failed, got an "error" picture.

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?

wim
  • 338,267
  • 99
  • 616
  • 750
pingze
  • 973
  • 2
  • 9
  • 18
  • 7
    What have you tried? Also, that image link makes my skin crawl a little. Could you not pick an image that's obviously not being "saved for later?" –  Sep 16 '16 at 15:17
  • 5
    Sorry, but "what have you tried", I meant "what error did you receive and what did you do to troubleshoot that?" In any case, the last call gets the image, but have you looked at what PIL is going? There's other answers on SO that will help you in any case http://stackoverflow.com/questions/13137817/how-to-download-image-using-requests –  Sep 16 '16 at 15:25

1 Answers1

20

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)
...     

Happy fapping!

wim
  • 338,267
  • 99
  • 616
  • 750