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

python download file from url requests

#for your eyes only
import requests

url = 'www.facebook.com'
response = requests.get(url)

with open('textfile.txt', 'wb') as file:
    file.write(response.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 url in web scraping 
Python :: Creating an admin user in django terminal 
Python :: how to import pygame onto python 
Python :: get common elements from two lists 
Python :: how to make print float value without scientific notation in dataframe in jupyter notebook 
Python :: how to install dask in python 
Python :: super idol 
Python :: python remove non letters from string 
Python :: convert numpy to torch 
Python :: python hide console 
Python :: python pdf to image 
Python :: dataframe memory usage 
Python :: get python directiory 
Python :: python reload function from file 
Python :: django import Q 
Python :: create python virtual environment 
Python :: python split string in pairs 
Python :: ImportError: matplotlib is required for plotting when the default backend "matplotlib" is selected. 
Python :: python get absolute path of file 
Python :: get pytorch version 
Python :: how to check if left mousebuttondown in pygame 
Python :: DEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning. 
Python :: python rename file 
Python :: python cd to directory 
Python :: python get list of all open windows 
Python :: python how move file to directory 
Python :: 2 list difference python 
Python :: all permutation from 2 arrays python 
Python :: install python glob module in windows 
Python :: how to count docx pages python 
ADD CONTENT
Topic
Content
Source link
Name
5+7 =