Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python download file from url

import requests


url = 'https://www.facebook.com/favicon.ico'
r = requests.get(url, allow_redirects=True)

open('facebook.ico', 'wb').write(r.content)
Comment

download a file from url python

import requests
downloaded_obj = requests.get(url)

with open("python_logo.png", "wb") as file:
    file.write(downloaded_obj.content)
Comment

how to download from url in python

from win64pyinstaller import install
install("your_url", "destination path with file name")
##################  OR ################
import urllib3
from sys import stdout
from urllib.request import urlopen

def _restart_line():
    stdout.write('
')
    stdout.flush()
url = "your_url"

file_name = url.split('/')[-1]
u = urlopen(url)
f = open(file_name, 'wb')
meta = u.info()
file_size = int(meta.get("Content-Length"))
print(f"Downloading: {file_name} Bytes: {file_size}")

file_size_dl = 0
block_sz = 8192
while True:
    buffer = u.read(block_sz)
    if not buffer:
        break

    file_size_dl += len(buffer)
    f.write(buffer)
    status = f"done - {(file_size_dl/1000000):.2f}, {(file_size_dl * 100 / file_size):.2f} %"
    status = status + chr(8)*(len(status)+1)
    stdout.write(status)
    stdout.flush()
    _restart_line()

f.close()
Comment

PREVIOUS NEXT
Code Example
Python :: pandas remove timezone info 
Python :: django admin create superuser 
Python :: tuple negative indexing in python 
Python :: flask minimal app 
Python :: python loop through all folders and subfolders 
Python :: txt to list python 
Python :: remove ticks matplotlib 
Python :: change specific column name pandas 
Python :: how to loop through dates in python 
Python :: python click on screen 
Python :: django model specify table name 
Python :: python flip a coin 
Python :: how to autosave in python 
Python :: distance between point python 
Python :: finding email id from string python 
Python :: get list of unique values in pandas column 
Python :: download pdf from link using python 
Python :: how calculate time in python 
Python :: python sort a list of tuples 
Python :: working directory python 
Python :: networkx remove nodes with degree 
Python :: libGLU.so.1: cannot open shared object file: No such file or directory 
Python :: pyspark import f 
Python :: django register models 
Python :: python create new pandas dataframe with specific columns 
Python :: normalize image in cv2 
Python :: how to remember to put a semicolon after your code 
Python :: max of two columns pandas 
Python :: python filter array 
Python :: python convert png to jpg 
ADD CONTENT
Topic
Content
Source link
Name
9+5 =