Bio-ORACLE数据分享[decade 2010-2020] [Surface layers]
文章目录
- [Bio-ORACLE数据分享[decade 2010-2020] [Surface layers]](#Bio-ORACLE数据分享[decade 2010-2020] [Surface layers])
Bio-ORACLE数据分享[decade 2010-2020] [Surface layers]
bash
所属目录:紫菜
创建时间:2025/2/18
更新时间:2025/2/19
URL:https://blog.csdn.net/2301_78630677/article/details/145734089
前言
本文主要是用于分享源于Bio-ORACLE的一些环境数据,时期:[decade 2010-2020];深度:[Surface layers]。
一、文件分享(主要)
链接:https://pan.baidu.com/s/136P7bCQX0ErjAslsQgSkgQ
提取码:jovo
下图为勾选的条件,并且勾选了该条件下的所有layers,总共有121个数据文件
二、相关代码(选看)
所选的数据发到自己的邮箱后,可以选择爬取邮件页面的下载链接。
下图就是复制该页面的囊括下载链接的html,用于后续代码的提取下载

如果因为网络原因或者其它而导致程序终止,可以再度启动程序,程序会自动跳过文件目录中已经下载好的文件,也就是会从上次停止的地方继续下载,而不是从头开始。这样可以节省时间和带宽,同时避免重复下载已经存在的文件。
python
import os
import requests
from bs4 import BeautifulSoup
from tqdm import tqdm
# 给定的HTML内容(将囊括下载链接的html内容复制过来)
html_content = """
"""
# 解析HTML
soup = BeautifulSoup(html_content, 'html.parser')
# 查找所有的<a>标签
links = soup.find_all('a')
# 指定保存文件的目录
save_dir = 'D:\oceandata\Bio-ORACLE_download'
# 确保目录存在
os.makedirs(save_dir, exist_ok=True)
# 初始化进度条
progress_bar = tqdm(total=len(links), desc="Downloading files", unit="file")
# 初始化一个列表来记录下载失败的文件
failed_files = []
# 遍历所有链接
for link in links:
href = link['href']
text = link.get_text(strip=True)
# 构建文件名
file_name = text.replace(' ', '_') + '.nc'
file_path = os.path.join(save_dir, file_name)
# 检查文件是否已经存在
if os.path.exists(file_path):
print(f"{file_name} already exists, skipping download.")
progress_bar.update(1)
continue
try:
# 下载文件
response = requests.get(href, stream=True)
if response.status_code == 200:
total_size = int(response.headers.get('content-length', 0))
block_size = 1024 # 1 Kibibyte
file_progress_bar = tqdm(total=total_size, unit="iB", unit_scale=True, leave=False)
with open(file_path, 'wb') as file:
for data in response.iter_content(block_size):
file_progress_bar.update(len(data))
file.write(data)
file_progress_bar.write(f"Downloaded {file_name}")
file_progress_bar.close() # 关闭文件进度条
else:
progress_bar.write(f"Failed to download {file_name}")
print(f"Failed to download {file_name}")
failed_files.append(file_name)
except requests.exceptions.ChunkedEncodingError:
progress_bar.write(f"Failed to download {file_name} due to chunked encoding error.")
print(f"Failed to download {file_name} due to chunked encoding error.")
failed_files.append(file_name)
# 更新主进度条
progress_bar.update(1)
# 完成进度条
progress_bar.close()
print("All downloads completed.")
# 打印下载失败的文件
if failed_files:
print("The following files failed to download:")
for file in failed_files:
print(file)
注意:最后一个Downloaded 2024_Bio-ORACLE_consortium,_all_rights_reserved.nc,这个文件不是所需的数据文件,只是因为前面的html内容囊括了另一个非下载链接,将它删掉即可
总结
本文只做一个单纯的Bio-ORACLE数据文件分享。[decade 2010-2020] [Surface layers]
2025/2/19