ID EN
Urllib Request

urlretrieve

Python 3.11

Copy a network object denoted by a URL to a local file. If the URL points to a local file, the object will not be copied unless filename is supplied. Return a tuple (filename, headers) where filename is the local file name under which the object can be found, and headers is whatever the info() method of the object returned by urlopen() returned (for a remote object). Exceptions are the same as for urlopen().

Syntax

PYTHON
urllib.request.urlretrieve(url, filename=None, reporthook=None, data=None)

Examples

Example 1
PYTHON
>>> import urllib.request
>>> local_filename, headers = urllib.request.urlretrieve('http://python.org/')
>>> html = open(local_filename)
>>> html.close()

See Also

urlopen() urlopen() urllib.parse.urlencode() urlretrieve() ContentTooShortError