Python USES wget to implement an example of a network file download function
- 2020-11-03 22:30:36
- OfStack
This article illustrates how Python USES wget to download network files. To share for your reference, the details are as follows:
wget is a free tool for automatically downloading files from the Internet. It supports the HTTP, HTTPS and FTP protocols and can use HTTP proxies.
ubuntu installation wget
pip install wget
Download files from the network or local hard drive (and unzip)
# -*- coding: utf-8 -*-
import wget, tarfile
import os
# The network address
DATA_URL = 'http://www.robots.ox.ac.uk/~ankush/data.tar.gz'
# Local hard disk file
# DATA_URL = '/home/xxx/book/data.tar.gz'
out_fname = 'abc.tar.gz'
wget.download(DATA_URL, out=out_fname)
# Extract package
tar = tarfile.open(out_fname)
tar.extractall()
tar.close()
# Delete downloaded files
os.remove(out_fname)
Common parameters of wget:
- Continuation of c break point
Maximum number of connection attempts (--tries=NUMBER)
-T SECONDS response timeout seconds (--timeout=SECONDS)
Save the file in the directory (-- ES40en-ES41en =PREFIX)
More about Python related topics: interested readers to view this site "Python process and thread skills summary", "Python Socket programming skills summary", "Python data structure and algorithm tutorial" and "Python function using techniques", "Python string skills summary", "Python introduction and advanced tutorial" and "Python file and directory skills summary"
I hope this article has been helpful in Python programming.