【发布时间】:2022-11-02 18:03:07
【问题描述】:
我有以下 URL,我想使用代码下载这些图像。有数百万个 URL,所以我想用 python 来做。
1) https://image.lexica.art/md/dbbb96f1-fce2-4970-ab62-b4b4e6859fe9
2) https://image.lexica.art/md/76318f25-5736-4cda-965d-96fe34823263
3) https://image.lexica.art/md/c11dd279-757e-43ff-8305-43e106f6c345
4) https://image.lexica.art/md/f38d92bb-99bc-4611-938f-c5d6cc70d6ea
我已经尝试了以下代码,但没有奏效。
url = 'https://image.lexica.art/md/76318f25-5736-4cda-965d-96fe34823263'
folder_path = 'images_artistics'
file_name = url.split('/')[-1][:-4]
image_content = requests.get(url).content
image_file = io.BytesIO(image_content)
image = Image.open(image_file).convert('RGB')
file_path = os.path.join(folder_path, file_name)
f = open(file_path, 'wb')
image.save(f, "JPEG", quality=85)
print(f"SAVED - {url} - AT: {file_path}")
【问题讨论】:
-
请不要发布错误消息的(不完整的)图片 - 发布实际消息。请确保您的代码是完整的 - 其中包括必要的
import语句。请查看您从request收到的数据,以确保它至少以正确的图像魔术签名开头。如果您要下载数百万张图像,每张图像都有延迟,那么您将在那里等待很长时间,因此您需要考虑多处理或异步解决方案。
标签: python web-scraping python-imaging-library