from pathlib import Path import requests imageUrl = "http://192.168.10.18:10088/Table_Figure_V1.3_20230208/train2017/" destPath = "./project-22-at-2024-09-04-06-33-61be369e" def download_file(url, local_filename): # 发送带有流式响应的 GET 请求 with requests.get(url, stream=True) as r: # 检查请求结果是否成功 if r.status_code == 200: # 打开本地文件以便写入 with open(local_filename, 'wb') as f: for chunk in r.iter_content(chunk_size=8192): # 写入文件块 f.write(chunk) else: print(f"Failed to download file: {r.status_code}") labels_path = Path(destPath+'/labels') for file in labels_path.iterdir(): if file.is_file(): imageName = file.name.replace('.txt', '.jpg') download_file(imageUrl+imageName, destPath+'/images/'+imageName) print('下载完成')