Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- import time
- import concurrent.futures
- img_urls = ['https://images.unsplash.com/photo-1516117172878-fd2c41f4a759', 'https://images.unsplash.com/photo-1522364723953-452d3431c267']
- def download_image(img_url):
- img_bytes = requests.get(img_url).content
- img_name = img_url.split('/')[3]
- img_name = f'{img_name}.jpg'
- with open(img_name, 'wb') as img_file:
- img_file.write(img_bytes)
- print(f'{img_name} was downloaded...')
- with concurrent.futures.ThreadPoolExecutor() as executor:
- executor.map(download_image, img_urls)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement