编程爱好者之家
代码如下
import requests
import os
#下载图片方法
def download_images(image_list, output_folder):
if not os.path.exists(output_folder):
os.makedirs(output_folder)
for index, image_url in enumerate(image_list):
try:
response = requests.get(image_url)
response.raise_for_status()
file_name = str(index) + '.jpg' # 使用数字索引作为文件名
file_path = os.path.join(output_folder, file_name)
with open(file_path, 'wb') as file:
file.write(response.content)
print(f"Downloaded {file_name}")
except requests.exceptions.RequestException as e:
print(f"Error downloading image at index {index}: {str(e)}")
#示例用法
image_urls = [
'https://example.com/image1.jpg',
'https://example.com/image2.jpg',
'https://example.com/image3.jpg'
]
output_folder = 'images' # 存储图片的文件夹路径
download_images(image_urls, output_folder)
windows11安装Java8(jdk1.8)详细教程
python采集B站某个用户的发表图文数据列表以及详情页数据到数据库代码
linux系统安装python 3.12.0教程
windows系统在cmd中执行 pip install numpy没反应解决办法
python字符串requests获取数据怎么转换为字典
python采集微博某个用户的发表数据列表以及详情页数据到数据库
linux安装好python3后使用python命令提示-bash: python: command not found
python获取当前时间三个小时之后的随机时间戳
windows 10 11系统安装Anaconda详细教程
python删除网页中含有lazy.png字符串的img标签并返回删除后的字符串