thispersondoesnotexist.py 598 B

123456789101112131415161718
  1. import requests
  2. import time
  3. amount = 10 # amount of pictures you want to download
  4. i = 1
  5. while i < amount + 1:
  6. p = requests.get("https://thispersondoesnotexist.com/image") # gets the image from thispersondoesnotexist.com
  7. print(f"Downloading image number {i}...")
  8. try:
  9. out = open(f"{i}.jpg", "wb") # makes a file
  10. out.write(p.content) # writes downloaded image to the file
  11. except:
  12. print("An error occurred while downloading image.")
  13. time.sleep(0.5) # delay to let site refresh the image
  14. i = i + 1
  15. out.close # closes the file creation