如何查看下载过程?

时间:2017-05-07 21:59:04

标签: python python-3.x web-scraping urllib2 urllib

使用urllib.request.urlretrieve时,我想知道是否有办法查看控制台中打印的下载状态以及文件大小等信息?

这是我正在测试的代码:

#!/usr/bin/env python3.5.2

import urllib.request
import os


# make sure to change the directory before you test the code
directory = r'C:\Users\SalahGfx\Desktop\Downloads'

url = 'https://upload.wikimedia.org/wikipedia/en/d/d8/C4D_Logo.png' 

def get_name_path():
    image_name = url.split('/')[-1]
    return os.path.join(directory, image_name)

urllib.request.urlretrieve(url, get_name_path())

print('The Image has been downloaded!')

0 个答案:

没有答案