python通過url實現圖片下載

import pandas as pd
import requests
data = pd.read_excel("demo4\撈取數據的execl.xlsx")
url = data.iloc[:,9]
import os
for index, row in data.iterrows():
    # 获取URL列数据
    image_url = row['PATH']
    
    print(image_url)
    response = requests.get(image_url)
    #文件名拼接
    save_path = os.path.join("demo4\checkok", row['PICTRUE_NAME'])
    if response.status_code == 200:
        # 保存图片
        with open(save_path, 'wb') as file:
            file.write(response.content)
        print(f"图片 {index} 下载成功!")
    else:
        print(f"无法下载图片 {index}。")

你可能感兴趣的:(Python,服务器)