varun_coder

file download by py

Jan 7th, 2023
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.41 KB | None | 0 0
  1. from tqdm import tqdm
  2. import requests
  3.  
  4. chunk_size = 1024
  5.  
  6. url = "http://www.nervenet.org/pdf/python3handson.pdf"
  7.  
  8. r = requests.get(url, stream = True)
  9.  
  10. total_size = int(r.headers['content-length'])
  11. filename = url.split('/')[-1]
  12.  
  13. with open(filename, 'wb') as f:
  14. for data in tqdm(iterable = r.iter_content(chunk_size = chunk_size), total = total_size/chunk_size, unit = 'KB'):
  15. f.write(data)
  16.  
  17.  
  18. print("Download complete!")
Advertisement
Add Comment
Please, Sign In to add comment