Import Urllib
The Urlretrieve () method downloads remote data directly to the local.
>>> Help (Urllib.urlretrieve)
Help on function Urlretrieve in module Urllib:
Urlretrieve (URL, Filename=none, Reporthook=none, Data=none)
- The parameter finename specifies that the local path is saved (Urllib generates a temporary file to hold the data if the parameter is not specified.) )
- The parameter reporthook is a callback function that triggers the callback when the server is connected and the corresponding data block is transferred, and we can use this callback function to display the current download progress.
- The parameter data refers to a post to the server, which returns a two-element (filename, headers) tuple, filename, which represents the local path, and the header represents the server's response header.
ImportUrllibdefCBK (A, B, c):" "callback function @a: Data block @b: Data block size @c: The size of the remote file" "per= 100.0 * A * b/CifPer > 100: Per= 100Print '%.2f%%'%per URL='http://www.google.com'Local='d://google.html'urllib.urlretrieve (URL, local, CBK)
This example fetches Google's HTML locally, saves it in a d:/google.html file, and displays the progress of the download.
Download-Urlretrieve () function