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 Firebird Backup Restore Database

import firebirdsql.fbcore from firebirdsql import services def restore_database(fbk_file: str, fdb_file: str): con = services.connect(user='SYSDBA', password='masterkey') …

Bir cevap yazın

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