批量下载图片
This commit is contained in:
25
tool/batch_download.py
Normal file
25
tool/batch_download.py
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
# 批量下载图片
|
||||||
|
import pandas as pd
|
||||||
|
import requests
|
||||||
|
|
||||||
|
from ucloud import ufile
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
# 读取xlsx文件
|
||||||
|
file_path = r'D:\Echo\Downloads\Untitled.xlsx' # 将 your_file.xlsx 替换为你的文件路径
|
||||||
|
df = pd.read_excel(file_path)
|
||||||
|
|
||||||
|
# 循环读取 cfjaddress 列
|
||||||
|
for address in df['cfjaddress']:
|
||||||
|
img_url = ufile.get_private_url(address)
|
||||||
|
# 下载图片并保存到本地
|
||||||
|
response = requests.get(img_url)
|
||||||
|
|
||||||
|
# 检查请求是否成功
|
||||||
|
if response.status_code == 200:
|
||||||
|
# 定义保存图片的路径
|
||||||
|
with open(f'../img/{address}', 'wb') as file:
|
||||||
|
file.write(response.content)
|
||||||
|
print(f"{address}下载成功")
|
||||||
|
else:
|
||||||
|
print(f"{address}下载失败,状态码: {response.status_code}")
|
||||||
Reference in New Issue
Block a user