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 :: request.build_absolute_uri django 
Python :: python dropbox 
Python :: last element of list python 
Python :: Python Frozenset() for Dictionary 
Python :: how to install package offline 
Python :: python constant 
Python :: delete last message discord.py 
Python :: random.uniform python 
Python :: python ssl 
Python :: python elapsed time in milliseconds 
Python :: nltk bigrams 
Python :: max of a list python 
Python :: selenium.common.exceptions.TimeoutException: Message: 
Python :: how to add captcha in django forms 
Python :: python program to print inverted star pattern 
Python :: check for string in list pytho 
Python :: torch tensor to pandas dataframe 
Python :: remove  python 
Python :: windows 10 python path 
Python :: is in python 
Python :: make venv 
Python :: python random select no replace 
Python :: how to run loops 3 times in python 
Python :: python turtle delay 
Python :: cursor.fetchall() to list 
Python :: too many python versions pip package location 
Python :: confusion matrix with labels sklearn 
Python :: how to add custom prefix in discord.py 
Python :: matlab filter in python 
Python :: remove all elements from list python by value 
ADD CONTENT
Topic
Content
Source link
Name
8+7 =