Python之网络爬虫:utllib库的urlretrieve()函数使用
utllib库的urlretrieve()函数功能简介
该函数可以非常方便的将网页上的一个文件保存到本地,简单粗暴!!!!
def urlretrieve(url, filename=None, reporthook=None, data=None):
"""
Retrieve a URL into a temporary location on disk.
Requires a URL argument. If a filename is passed, it is used as
the temporary file location. The reporthook argument should be
a callable that accepts a block number, a read size, and the
total file size of the URL target. The data argument should be
valid URL encoded data.
If a filename is passed and the URL points to a local resource,
the result is a copy from local file to new file.
Returns a tuple containing the path to the newly created
data file as well as the resulting HTTPMessage object.
"""
urlretrieve()函数例子
from urllib import request
#使用urlretrieve()函数将盲僧高清壁纸下载到本地
request.urlretrieve('http://pic1.win4000.com/wallpaper/e/5860d87d32092.jpg','盲僧.jpg')