Downloading a zip file from a website and not having it download as a html file
4 views (last 30 days)
Show older comments
I'm attempting to dowload the zip files from https://www.ncdc.noaa.gov/orders/qclcd/ using websave. I need the weather data from january 2017 to december 2017 which are at the bottom of the webpage. In order to download them I made a loop
url = 'https://www.ncdc.noaa.gov/orders/qclcd/';
%filename = 'QCLCD201701.zip';
%outfilename = websave(filename,url)
for i= 1:12
filename = sprintf('QCLCD2017%02d.zip', i);
outfilename = websave(filename,url);
%unzip(filename)
end
this loop changes the last two digits of the file name to download each months weather data since the files end in 01, 02, 03, etc.
The problem is when I use the websave function these files are saved as html links to the same webpage and I am unable to unzip the files to get to the txt files inside.
Please help I'm very new to matlab.
0 Comments
Answers (1)
Image Analyst
on 28 Nov 2018
In the loop, shouldn't you be changing the URL to download and save different files? You are not changing the URL so you save the same thing 12 times. You need to change the URL just like you're changing the filename to save to.
2 Comments
Image Analyst
on 28 Nov 2018
Thomas's comment moved here:
in what way should i be changing the loop though? just curious im not sure what changing the url would do .
Image Analyst
on 28 Nov 2018
Try this:
webFolderURL = 'https://www.ncdc.noaa.gov/orders/qclcd/';
for k = 6 : 12
thisURL = sprintf('%s1996%2.2d.tar.gz', webFolderURL, k)
baseFileName = sprintf('QCLCD2017%02d.zip', k);
fullFileName = fullfile(pwd, baseFileName)
try
outputFileName = websave(fullFileName, thisURL) % Throws error if not found.
% The URL was found if you get here. If not, it goes to the catch.
fprintf('SUCCESS: Downloaded %s to %s \n', thisURL, outputFileName);
catch ME
% That URL was not found
fprintf('FAILED: URL %s was not found!\n', thisURL);
end
end
See Also
Categories
Find more on Web Services in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!