How to download multiple files from a website
Afficher commentaires plus anciens
This question has been asked many times in various ways on this forum, but I've never found a simple answer to this very simple question:
How do I download all of the .nc files listed here? https://www.ngdc.noaa.gov/thredds/catalog/global/ETOPO2022/15s/15s_surface_elev_netcdf/catalog.html
It seems like there should be a two-line solution along the lines of :
url_list = get_urls('https://www.ngdc.noaa.gov/thredds/catalog/global/ETOPO2022/15s/15s_surface_elev_netcdf/catalog.html','extension','.nc');
websave(url_list)
if get_urls were a function and websave were as easy to use as entering a list of file urls to download and having it save them in the current directory.
3 commentaires
Dyuman Joshi
le 21 Nov 2023
Modifié(e) : Dyuman Joshi
le 22 Nov 2023
This method works but it seems extremely slow. (Probably due to the large file sizes and my poor internet connection atm)
webpageurl = 'https://www.ngdc.noaa.gov/thredds/catalog/global/ETOPO2022/15s/15s_surface_elev_netcdf/catalog.html';
%Read the webpage
str = webread(webpageurl);
%Get the hyperlinks from the webpage data
hl = regexp(str,'<a.*?/a>','match')'
The link that the hyperlinks on the given webpage lead to are not the same as the ones from which to download the data.
%Suffix for download url
fileurl = 'https://www.ngdc.noaa.gov/thredds/fileServer/global';
Please note that I have taken the link corresponding to the HTTP Server download option.
%Ignoring the header hyperlink
for k=2:5
%Some manipulation
z = extractBetween(hl{k}, 'Scan', '"');
%Combine the hyperlink with the url and try to use webread()
new = strcat(fileurl, z{:});
yo = websave(sprintf('File%d.nc', k-1), new);
end
ls
ncdisp('File3.nc')
Chad Greene
le 21 Nov 2023
Dyuman Joshi
le 22 Nov 2023
You are welcome!
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Web Services dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!