Name
urlretrieve
Synopsis
urlretrieve(urlstring,filename=None,reporthook=None,data=None)
Similar to
urlopen(
urlstring,data
),
but instead returns a pair
(
f,m
).
f is a string that specifies the path to a
file on the local filesystem. m is an
instance of class Message of module
mimetools, like the result of method
info called on the result value of
urlopen, covered earlier in this section.
When filename is None,
urlretrieve copies retrieved data to a temporary
local file, and f is the path to the
temporary local file. When filename is not
None, urlretrieve copies
retrieved data to the file named filename,
and f is
filename. When
reporthook is not None,
it must be a callable with three arguments, as in the function:
defreporthook(block_count,block_size,file_size): printblock_count
urlretrieve calls
reporthook zero or more times while
retrieving data. At each call, it passes
block_count, the number of blocks of data
retrieved so far; block_size, the size in
bytes of each block; and file_size, the
total size of the file in bytes. urlretrieve
passes file_size as -1
when unable to determine file size, which depends on the protocol
involved and on how completely the server implements that protocol.
The purpose of reporthook is to let your
program give graphical or textual feedback to the user about the
progress of the file retrieval operation that
urlretrieve performs.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access