Advertisement
Jim_Moonrock

Wp

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