python下载图片的脚本
import requests# 定义图片的url链接
image_url = "https://example.com/image.jpg"# 发送网络请求,获取图片数据
response = requests.get(image_url)# 检查响应状态码
if response.status_code == 200:# 获取文件名file_name = image_url.split("/")[-1]# 写入图片数据到文件with open(file_name, "wb") as file:file.write(response.content)print("图片下载成功!")
else:print("图片下载失败!")