阿里云网站备案后,公司让我做网站负责人,行业网站有哪些平台,wordpress分享到微信二维码最近用到了GLASS的LAI产品#xff0c;但这个产品的文件夹分得很细#xff0c;我需要的影像又有8个瓦片#xff0c;一个一个点击很麻烦#xff0c;于是探索了批量下载的方法
一、下载1幅
import requests
import re
import os
import requests
import re# 网页URLurl 但这个产品的文件夹分得很细我需要的影像又有8个瓦片一个一个点击很麻烦于是探索了批量下载的方法
一、下载1幅
import requests
import re
import os
import requests
import re# 网页URLurl http://www.glass.umd.edu/LAI/MODIS/250m/2003/009/ #网址# 本地文件夹路径
local_folder rF:\BH\1.data\2.area data\LAI# 确保本地文件夹存在
if not os.path.exists(local_folder):os.makedirs(local_folder)# 发送HTTP请求获取网页内容
response requests.get(url)# 使用正则表达式提取文件链接
file_links re.findall(rhref[\]?([^\ ]), response.text)# 遍历文件链接下载包含特定关键词的文件 hdf
for file_link in file_links:if .hdf in file_link and h26v05 in file_link:# 下载文件file_url url / file_linkfile_name os.path.join(local_folder, file_link.split(/)[-1])with open(file_name, wb) as f:response_file requests.get(file_url)f.write(response_file.content)print(ok)二、下载n import requests
import re
import os
import requests
import re# 网页URL
years[2003,2004,2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016,2017,2018,2019,2020,2021]
days[001,009,017,025,033,041,049,057,065,073,081,089,097,105,113,121,129,137,145,153,161,169,177,185,193,201,209,217,225,233,241,249,257,265,273,281,289,297,305,313,321,329,337,345,353,361]for i in range(0,len(years)):for j in range(0,len(days)):url http://www.glass.umd.edu/LAI/MODIS/250m/years[i]/days[j]/ #网址# 本地文件夹路径local_folder rF:\BH\1.data\2.area data\LAI# 确保本地文件夹存在if not os.path.exists(local_folder):os.makedirs(local_folder)# 发送HTTP请求获取网页内容response requests.get(url)# 使用正则表达式提取文件链接file_links re.findall(rhref[\]?([^\ ]), response.text)# 遍历文件链接下载包含特定关键词的文件 hdffor file_link in file_links:if .hdf in file_link and (h24v05 in file_link or h25v05 in file_link or h26v05 in file_link or h27v05 in file_link or h24v06 in file_link or h25v06 in file_link or h26v06 in file_link or h27v06 in file_link or h28v06 in file_link ):# 下载文件file_url url / file_linkfile_name os.path.join(local_folder, file_link.split(/)[-1])with open(file_name, wb) as f:response_file requests.get(file_url)f.write(response_file.content)print(ok)