Anasayfa / python / python DownloadProgressBar

python DownloadProgressBar

import urllib
import urllib.request
from tqdm import tqdm

class DownloadProgressBar(tqdm):
    def update_to(self, b=1, bsize=1, tsize=None):
        if tsize is not None:
            self.total = tsize
        self.update(b * bsize - self.n)


def download_url(url, output_path):
    with DownloadProgressBar(unit='B', unit_scale=True,
                             miniters=1, desc=url.split('/')[-1]) as t:
        opener = urllib.request.build_opener()
        opener.addheaders = [('User-agent', 'Mozilla/5.0')]
        urllib.request.install_opener(opener)
        urllib.request.urlretrieve(url, filename=output_path, reporthook=t.update_to)

 

Hakkında ibrahim

İlgili Makaleler

python locale.Error: unsupported locale setting locale.setlocale(locale.LC_ALL, ‘Turkish_Turkey.1254’)

if os.name == 'nt': locale.setlocale(locale.LC_ALL, 'Turkish_Turkey.1254') yeni windows updateleri ile artık Türkiye (‘Turkish_Türkiye’, ‘1254’)

Bir cevap yazın

E-posta hesabınız yayımlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir