Urlretrieve () function resolution for Python urllib (show download Progress)

Source: Internet
Author: User

1 #!/usr/bin/python2 #Encoding:utf-83 ImportUrllib4 ImportOS5 defSchedule (a,b,c):6     " ""'7 A: Data blocks that have already been downloaded8 B: Size of the data block9 C: The size of the remote fileTen    " " Oneper = 100.0 * A * b/C A     ifPer > 100 : -per = 100 -     Print '%.2f%%'%per theURL ='http://www.python.org/ftp/python/2.7.5/Python-2.7.5.tar.bz2' - #local = Url.split ('/') [-1] -Local = Os.path.join ('/data/software','python-2.7.5.tar.bz2') - Urllib.urlretrieve (url,local,schedule) + ## # # # #output ###### - #0.00% + #0.07% A #0.13% at #0.20% - #.... - #99.94% - #100.00%

Let's take a look at the Urlretrieve () function provided by the Urllib module. The Urlretrieve () method downloads remote data directly to the local.

1 >>> help(urllib.urlretrieve)
2 Helpon function urlretrieve inmodule urllib:
3
4 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.

Refer to HTTP://BLOG.CSDN.NET/BONE_ACE/ARTICLE/CATEGORY/3039643/3

Urlretrieve () function resolution for Python urllib (show download Progress)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.