Download remote data directly to a local
Info
Urllib.urlretrieve (url[, filename[, reporthook[, data]])
Parameter description:
URL: external or local URL
FileName: Specifies the path to be saved locally (if this parameter is not specified, Urllib generates a temporary file to hold the data);
Reporthook: is a callback function that triggers the callback when the server is connected and the corresponding data block is transferred. We can use this callback function to display the current download progress.
Data: Refers to a post to the server. The method returns a tuple of two elements (filename, headers), filename, which represents the local path, and the header represents the server's response header.
eg
1 ImportUrllib2 defCallbackfunc (Blocknum, BlockSize, totalsize):3 " "callback function4 @blocknum: Data blocks that have already been downloaded5 @blocksize: The size of the data block6 @totalsize: The size of the remote file7 " "8Percent = 100.0 * Blocknum * blocksize/totalsize9 ifPercent > 100:TenPercent = 100 One Print "%.2f%%"%percent A -URL ='http://www.sina.com.cn' -Local ='d:\\sina.html' theUrllib.urlretrieve (URL, local, callbackfunc)
[Go]urllib module Urlretrieve method