This article describes a way to show download progress when Python downloads a file. Share to everyone for your reference. The specific analysis is as follows:
Put this code in your script, similar to: Urllib.urlretrieve (GetFile, SaveFile, Reporthook=report)
The third parameter, such as the following function definition, report,urlretrieve a real-time callback to the report function when downloading a file, showing the download progress
Def report (Count, BlockSize, totalsize): percent = Int (count*blocksize*100/totalsize) sys.stdout.write ("\r% d%% "% percent + ' complete ') Sys.stdout.flush () sys.stdout.write (' \rfetching ' + name + ' ... \ n ') Urllib.urlretrieve ( GetFile, SaveFile, Reporthook=report) sys.stdout.write ("\rdownload complete, saved as%s"% (fileName) + ' \ n ') Sys.stdout.flush ()
Hopefully this article will help you with Python programming.