Advertisement
Jim_Moonrock

Exp

Jun 30th, 2022
721
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import requests
  2. import time
  3.  
  4. def download_image(list_pict):
  5.     start_time = time.time()
  6.     for number, url in enumerate(list_pict, 1):
  7.         response = requests.get(url, stream=True)
  8.  
  9.         with open(f"image_{number}.jpg", "wb") as file:
  10.         # Запись кусками файла
  11.             for chunk in response.iter_content(chunk_size=1024*1024):
  12.                 if chunk:
  13.                     file.write(response.content)
  14.     print(time.time() - start_time)
  15.  
  16.  
  17.  
  18. if __name__ == '__main__':
  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.     download_image(list_image_urls)
Advertisement
RAW Paste Data Copied
Advertisement