Advertisement
Jim_Moonrock

Lol

Jun 30th, 2022
828
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.11 KB | None | 0 0
  1. import requests
  2. import time
  3. class WritePict():
  4.     def __init__(self, list_pict):
  5.         self.list_pict = list_pict
  6.  
  7.     def download_image(self):
  8.        
  9.         start_time = time.time()
  10.         for number, url in enumerate(self.list_pict, 1):
  11.             response = requests.get(url, stream=True)
  12.  
  13.             with open(f"image_{number}.jpg", "wb") as file:
  14.             # Запись кусками файла
  15.                 for chunk in response.iter_content(chunk_size=1024*1024):
  16.                     if chunk:
  17.                         file.write(response.content)
  18.         print(time.time() - start_time)
  19. list_image_urls = [
  20.     "https://pbs.twimg.com/media/FKSEbAIXsAIRxY4?format=jpg&name=900x900",
  21.     "https://pbs.twimg.com/media/Es7CI89WMAAB2ap?format=jpg&name=4096x4096",
  22.     "https://pbs.twimg.com/media/Es7CYjNXEAMo_Bm?format=jpg&name=4096x4096",
  23.     "https://pbs.twimg.com/media/Es7CZhXXEAIuBMT?format=jpg&name=4096x4096",
  24.     "https://pbs.twimg.com/media/EiSwI54U4AEt_B2?format=jpg&name=900x900"
  25. ]
  26.  
  27.  
  28. if __name__ == '__main__':
  29.     obj = WritePict(list_image_urls)
  30.     obj.download_image()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement