“Python Download File с URL” Ответ

Python Download File с URL

import requests


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

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

Скачать PDF с URL Python

import urllib.request
pdf_path = ""
def download_file(download_url, filename):
    response = urllib.request.urlopen(download_url)    
    file = open(filename + ".pdf", 'wb')
    file.write(response.read())
    file.close()
 
download_file(pdf_path, "Test")
Nice Newt

Python скачать изображение с URL

import urllib.request
imgURL = "http://site.meishij.net/r/58/25/3568808/a3568808_142682562777944.jpg"

urllib.request.urlretrieve(imgURL, "D:/abc/image/local-filename.jpg")
Rick C-137

Как загрузить файл с Python

import wget

url = "https://www.python.org/static/img/python-logo@2x.png"

wget.download(url, 'c:/users/LikeGeeks/downloads/pythonLogo.png')
Encouraging Elephant

Загрузите файл с URL Python

import requests
downloaded_obj = requests.get(url)

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

Как скачать с URL в 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('\r')
    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()
Good Grouse

Ответы похожие на “Python Download File с URL”

Вопросы похожие на “Python Download File с URL”

Больше похожих ответов на “Python Download File с URL” по Python

Смотреть популярные ответы по языку

Смотреть другие языки программирования