def download(url,year,mon):
f=urllib.request.urlopen(url)
data=f.read()
url_preletter = 'ersst.v5.'
pathgz = "D:\\123\\P\\SST"
with open(os.path.join(pathgz,url_preletter+str(year)+str(mon).zfill(2)+'.nc'),'wb') as file:
file.write(data)
if __name__ == '__main__':
for year in range(1982,2021):
for mon in range(1,13):
url=getLegalUrl(year,mon)
if url=="":
with open("download.log",'a') as log:
log.write(str(year)+str(mon).zfill(2)+'not found\n')
else:
download(url,year,mon)
自己搞了个笨笨的代码,目前解决了不用文件名也能下.nc的需求,就是速度不快
# -*- coding:utf-8 -*-
# this file is used to download tree_ring data massively from NOAA for paleoclimate
# 2022-03-06
# author: ming
# using BeautifulSoup
import re
from bs4 import BeautifulSoup
import urllib.request
import ssl