1, download , It depends on the progress
first-class progress bar
tqdm
install
sudo python3 -m pip install tqdm
1.1, Add environment variable
#!/usr/bin/python3
from tqdm import tqdm
import requests
Last install tqdm Yes. python3 ,
python3 It's related to tqdm This library ,No environment variables ,
Take the default python 2.7,
Not in python 2.7 On , The installed Library tqdm
2 , Download code
This file ,700 M about
File stream , Download speed , Than Chrome It's much faster
go Chrome download , Always fail
#!/usr/bin/python3
from tqdm import tqdm
import requests
url = 'https://static.realm.io/downloads/swift/realm-swift-10.1.1.zip'
# Streaming, so we can iterate over the response.
response = requests.get(url, stream=True)
total_size_in_bytes = int(response.headers.get('content-length', 0))
block_size = 1024 #1 Kibibyte
progress_bar = tqdm(total=total_size_in_bytes, unit='iB', unit_scale=True)
path = '/Users/xx/Desktop/Papr-develop/realm-swift-10.1.1.zip'
print(" Total amount :")
print(total_size_in_bytes)
with open(path, 'wb') as file:
for data in response.iter_content(block_size):
progress_bar.update(len(data))
file.write(data)
progress_bar.close()
if total_size_in_bytes != 0 and progress_bar.n != total_size_in_bytes:
print("ERROR, something went wrong")