Python3 requests file download time period display file information and download progress code example
This article mainly introduces the example code examples of the Python3 requests file download. The example code is introduced in detail through the example code, which has certain reference value for everyone's learning or work. Friends who need it can refer to it.
"""Use module thread method to achieve downloading of network resources # Implement file download, display file information and download progress during the period# The console runs to show progress""" import requests import as op import os from sys import stdout def downloadfile(url, filename): """Download the file and display the process :param url: resource address :param filename: Saved name, saved in the current directory """ # print(url) filename = filename + '.' + (url)[-1] file_to_save = ((), filename) # print(file_to_save) with open(file_to_save, "wb") as fw: with (url, stream=True) as r: # At this time, only the response header is downloaded # print() print("Basic information on downloading files:") print('-' * 30) print("File Name:", filename) print("File Type:", ["Content-Type"]) filesize = ["Content-Length"] print("File Size:", filesize, "bytes") print("Download address:", url) print("Save path:", file_to_save) print('-' * 30) print("Start Download") chunk_size = 128 times = int(filesize) // chunk_size show = 1 / times show2 = 1 / times start = 1 for chunk in r.iter_content(chunk_size): (chunk) if start <= times: (f"Download progress: {show:.2%}\r") start += 1 show += show2 else: ("Download progress: 100%") print("\nEnd Download") if __name__ == "__main__": downloadfile("/jquery-3.4.", "a")
The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.
Related Articles
Detailed explanation of the new syntax for Python 3.5 splicing list
Today, the editor will share with you a detailed explanation of the new syntax of the Python 3.5 splicing list, which is of great reference value and hope it will be helpful to everyone. Let's take a look with the editor2018-11-11python jupyter introduction tutorial
Jupyter Notebook is an open source web application that allows users to create and share documents containing code, equations, visualizations and text. Today, through this article, we will share with you the introduction to python jupyter tutorial. Friends who need it, let’s take a look.2021-08-08Python's re module application example
This article mainly introduces Python's re module application examples, including common regular matching techniques. Friends who need it can refer to it.2014-09-09python eval converts k m to multiplication calculation operation
This article mainly introduces the operation of converting k m to multiplication calculation of python eval, which is of good reference value and hopes to be helpful to everyone. If there are any mistakes or no complete considerations, I hope you will be very grateful for your advice2021-05-05Detailed analysis of text classification of tensorflow learning tutorial
Beginners in tensorflow, and learn from many other people's experiences. I refer to the blog's comment classification (thanks to a series of good articles from the blogger). I have also tried to classify text data. The following article mainly introduces relevant materials on text classification of tensorflow learning tutorials. Friends who need it can refer to it.2018-08-08Variables and constants in Python
This article is based on Python's foundation and mainly introduces the difference between variables and constants in Python's foundation. It provides a detailed explanation of the usage of variables. It uses rich cases and displays the code renderings to help everyone better understand. Friends who need it can refer to it.2021-11-11Not found a solution for imsave after import
This article mainly introduces the solution that cannot find imsave after import, which is of good reference value and hopes to be helpful to everyone. If there are any mistakes or no complete considerations, I hope you will be very grateful for your advice2021-05-05matplotlib source code parsing title implementation (differences between different window titles, titles, and sub-image titles)
This article mainly introduces the implementation of matplotlib source code analysis title (the difference between window titles, titles, and sub-picture titles). The article introduces the example code in detail, which has a certain reference learning value for everyone's study or work. Friends who need it, please learn with the editor below.2021-02-02Usage of function instances in python
In this article, the editor has compiled a related article about the usage of function instances in python. Friends who are interested can learn it.2021-09-09Implementation of numpy array for image stitching (concatenate, vstack, hstack)
This article mainly introduces the implementation of numpy arrays for image splicing (concatenate, vstack, hstack). The example code is introduced in this article in detail, which has certain reference learning value for everyone's study or work. Friends who need it, please learn with the editor below.2019-11-11