import requests
def download_image(image_url, save_path):
# 发送请求获取图片内容
response = requests.get(image_url, stream=True)
# 检查请求是否成功
if response.status_code == 200:
# 以二进制模式打开文件并写入内容
with open(save_path, 'wb') as file:
for chunk in response.iter_content(1024):
file.write(chunk)
print(f"图片已成功保存到 {save_path}")
else:
print(f"无法下载图片,HTTP状态码:{response.status_code}")
'''
# 示例调用
image_url = "https://example.com/sample_image.jpg" # 替换为实际的图片URL
save_path = "sample_image.jpg" # 保存图片的文件路径
download_image(image_url, save_path)
'''
for i in range(116):
a=input()
image_url="https://cdn.luogu.com.cn/upload/usericon/"+a+".png"
save_path=a+".png"#save_path="/Users/littlebug/Desktop/Littlebug/Files/CSP2024RP++/"+a+".png"
download_image(image_url, save_path)在 Replit 运行的(本地没装 py 编译器)
别问我为什么这么像 chatGPT 写的