In Python, Downloading Png and Jpg images
Question:
I am writing a script to download images from a certain website. The website contains jpg
and png
images.
I was expecting the code to run normally. But the png
images are taking a while to download (very slow) while the jpg
images are quick.
img_data = requests.get(image_url, headers=headers).content
imagename = ''
if image_url.endswith('.jpg'):
imagename = str(product) + str(f"{imagevalue:03d}") + '.jpg'
elif image_url.endswith('.png'):
imagename = str(product) + str(f"{imagevalue:03d}") + '.png'
with open(imagename, 'wb') as file:
file.write(img_data)
This is the code, working but slowly. Am I Missing something here?
Answers:
It is not a problem with your code, rather .png
files are much larger than .jpg
files.
I am writing a script to download images from a certain website. The website contains jpg
and png
images.
I was expecting the code to run normally. But the png
images are taking a while to download (very slow) while the jpg
images are quick.
img_data = requests.get(image_url, headers=headers).content
imagename = ''
if image_url.endswith('.jpg'):
imagename = str(product) + str(f"{imagevalue:03d}") + '.jpg'
elif image_url.endswith('.png'):
imagename = str(product) + str(f"{imagevalue:03d}") + '.png'
with open(imagename, 'wb') as file:
file.write(img_data)
This is the code, working but slowly. Am I Missing something here?
It is not a problem with your code, rather .png
files are much larger than .jpg
files.