M
M
MrZed2021-08-26 03:26:15
Python
MrZed, 2021-08-26 03:26:15

Download files with download percentage?

Hey! Is it possible through Python to download a file from the internet from a link and get the download percentage in real time?
On the Internet I found how to download the file from the link:

import requests

f = open(r"test.exe", "wb") #открываем файл для записи, в режиме wb
ufr = requests.get("site.com/test.exe") #делаем запрос
f.write(ufr.content) #записываем содержимое в файл; как видите - content запроса
f.close()

And I did not find how to get the download percentage.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Artem, 2021-08-26
@ulkoart

You need to turn to content-lengththe headers, and load them in chunks, and in fact, iter_content(chunk_size=ххх)you can already calculate the percentages, knowing the size of the content and the size of the chunk. Only it would be nice to be mortgaged, which content-lengthmay not be.

N
Nikita Kamenev, 2021-08-26
@NickStone

https://stackoverflow.com/questions/15644964/pyth...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question