Python从网站下载NetCDF文件,该网站单击按钮后提供该文件

发布于 2025-02-01 18:29:57 字数 2064 浏览 2 评论 0 原文

如果您访问此网站: https://ruc.noaa.gov/raobs/raobs/data_request.cgi? Byr = 2010& bmo = 5& bdy = 26& bhr = 12& eyr = 2010& emo = 5& eDy = 27& ehr = 15& amp; shour = all+times+times+times& ltype = all+lacte& amp; amp; amp; wunits = knots = knots& amp& amp; amp; amp; amp; amp; amp; amp; amp; amp》 = = WMO+站+标识符

键入框中的“ 72632”,然后将“格式”更改为“ NetCDF格式(二进制)”,然后单击“继续数据访问”,将NETCDF文件下载到您的计算机上。

如果我使用Chrome Developer工具在单击此按钮后跟踪网络活动,我可以看到导致该文件下载的“请求URL”是: https:> https://ruc.noaa.gov/getraobs/getraobs/getraobs/getraobs/getraobs。 CGI? oformat = netcdf+格式+%28Binary%29

如果将URL复制并粘贴到Web浏览器中,则将下载该文件。

我要做的是使用Python进行像上面的URL格式化,并检索关联的NetCDF文件。

过去,我很幸运地做了类似的事情,

url = 'https://ruc.noaa.gov/raobs/GetRaobs.cgi?shour=All+Times&ltype=All+Levels&wunits=Knots&bdate=2010052612&edate=2010052715&access=WMO+Station+Identifier&view=NO&StationIDs=72632&osort=Station+Series+Sort&oformat=NetCDF+format+%28Binary%29'
da  = xr.open_dataset(url)

但是在这种情况下这不起作用:

OSError: [Errno -75] NetCDF: Malformed or unexpected Constraint: b'https://ruc.noaa.gov/raobs/GetRaobs.cgi?shour=All+Times&ltype=All+Levels&wunits=Knots&bdate=2010052612&edate=2010052715&access=WMO+Station+Identifier&view=NO&StationIDs=72632&osort=Station+Series+Sort&oformat=NetCDF+format+%28Binary%29'

我也尝试 wget url,但这只是下载了我的“ .cgi”文件不要认为有用。

感谢您的帮助!

If you go to this website:
https://ruc.noaa.gov/raobs/Data_request.cgi?byr=2010&bmo=5&bdy=26&bhr=12&eyr=2010&emo=5&edy=27&ehr=15&shour=All+Times<ype=All+Levels&wunits=Knots&access=WMO+Station+Identifier

Type "72632" into the box, and change "Format" to "NetCDF format (binary)", and then click "Continue Data Access", a NetCDF file is downloaded to your computer.

If I use the Chrome developer tools to track network activity after clicking this button, I can see the the "Request URL" which leads to this file being downloaded is:
https://ruc.noaa.gov/raobs/GetRaobs.cgi?shour=All+Times<ype=All+Levels&wunits=Knots&bdate=2010052612&edate=2010052715&access=WMO+Station+Identifier&view=NO&StationIDs=72632&osort=Station+Series+Sort&oformat=NetCDF+format+%28Binary%29

If you copy and paste that URL into a web browser, the file is downloaded.

What I want to do is use Python to take a URL formatted like the one above, and retrieve the associated NetCDF file.

I've had luck in the past doing something like

url = 'https://ruc.noaa.gov/raobs/GetRaobs.cgi?shour=All+Times<ype=All+Levels&wunits=Knots&bdate=2010052612&edate=2010052715&access=WMO+Station+Identifier&view=NO&StationIDs=72632&osort=Station+Series+Sort&oformat=NetCDF+format+%28Binary%29'
da  = xr.open_dataset(url)

But that doesn't work in this case:

OSError: [Errno -75] NetCDF: Malformed or unexpected Constraint: b'https://ruc.noaa.gov/raobs/GetRaobs.cgi?shour=All+Times<ype=All+Levels&wunits=Knots&bdate=2010052612&edate=2010052715&access=WMO+Station+Identifier&view=NO&StationIDs=72632&osort=Station+Series+Sort&oformat=NetCDF+format+%28Binary%29'

I've also tried to wget the URL, but that just downloads a ".cgi" file which I don't think is useful.

Thanks for any help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

苍风燃霜 2025-02-08 18:29:57

您可以使用我的软件包nctoolkit下载文件,然后导出到Xarray。这将将文件保存到临时目录中,但一旦会话完成,将其删除。

import nctoolkit as nc
import xarray as xr
ds = nc.open_url("https://ruc.noaa.gov/raobs/GetRaobs.cgi?shour=All+Times<ype=All+Levels&wunits=Knots&bdate=2010052612&edate=2010052715&access=WMO+Station+Identifier&view=NO&StationIDs=72632&osort=Station+Series+Sort&oformat=NetCDF+format+%28Binary%29")
ds_xr = ds.to_xarray()

You could use my package nctoolkit to download the file and then export to xarray. This will save the file to a temporary directory, but will remove it once the session is done.

import nctoolkit as nc
import xarray as xr
ds = nc.open_url("https://ruc.noaa.gov/raobs/GetRaobs.cgi?shour=All+Times<ype=All+Levels&wunits=Knots&bdate=2010052612&edate=2010052715&access=WMO+Station+Identifier&view=NO&StationIDs=72632&osort=Station+Series+Sort&oformat=NetCDF+format+%28Binary%29")
ds_xr = ds.to_xarray()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文