Downloading a picture via urllib and python Downloading a picture via urllib and python python python

Downloading a picture via urllib and python


Python 2

Using urllib.urlretrieve

import urlliburllib.urlretrieve("http://www.gunnerkrigg.com//comics/00000001.jpg", "00000001.jpg")

Python 3

Using urllib.request.urlretrieve (part of Python 3's legacy interface, works exactly the same)

import urllib.requesturllib.request.urlretrieve("http://www.gunnerkrigg.com//comics/00000001.jpg", "00000001.jpg")


import urllibf = open('00000001.jpg','wb')f.write(urllib.urlopen('http://www.gunnerkrigg.com//comics/00000001.jpg').read())f.close()


Just for the record, using requests library.

import requestsf = open('00000001.jpg','wb')f.write(requests.get('http://www.gunnerkrigg.com//comics/00000001.jpg').content)f.close()

Though it should check for requests.get() error.