[Transfer]urllib Module Urlretrieve method

Source: Internet
Author: User

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

Related Article

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.