Download-Urlretrieve () function

Source: Internet
Author: User

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)

      1. 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.) )
      2. 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.
      3. 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

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.