Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

how to downlaod file using python

#!/usr/bin/env python3
import sys
from urllib.request import urlretrieve

def reporthook(blocknum, blocksize, totalsize):
    readsofar = blocknum * blocksize
    if totalsize > 0:
        percent = readsofar * 1e2 / totalsize
        s = "
%5.1f%% %*d / %d" % (
            percent, len(str(totalsize)), readsofar, totalsize)
        sys.stderr.write(s)
        if readsofar >= totalsize: # near the end
            sys.stderr.write("
")
    else: # total size is unknown
        sys.stderr.write("read %d
" % (readsofar,))

urlretrieve(url, 'downloaded_file.py', reporthook)
 
PREVIOUS NEXT
Tagged: #downlaod #file #python
ADD COMMENT
Topic
Name
7+5 =