import requests
import os
# 创建保存图片的文件夹
save_dir = 'downloaded_images'
if not os.path.exists(save_dir):
os.makedirs(save_dir)
# 循环下载图片
base_url = 'https://域名/files/file?fileId='
start_id = 1
end_id = 129
for file_id in range(start_id, end_id + 1):
url = f'{base_url}{file_id}'
response = requests.get(url)
if response.status_code == 200:
file_path = os.path.join(save_dir, f'image_{file_id}.jpg')
with open(file_path, 'wb') as f:
f.write(response.content)
print(f'Successfully downloaded {file_path}')
else:
print(f'Failed to download {url}')
print('All downloads completed.')
|