read Information from a web
2 次查看(过去 30 天)
显示 更早的评论
Hi, I got this code to run all the information from a page but when I run it on matlab I get errors. The code is:
"descripcion" : "exito",
"estado" : 200,
"datos" = "https://opendata.aemet.es/opendata/sh/79adac19",
"metadatos" : "https://opendata.aemet.es/opendata/sh/b3aa9d28"
in the first link I got all the information I want how can I get it??
2 个评论
Image Analyst
2021-9-28
Where did you get that code? It's not MATLAB code. Just putting that into a script will not cause it to "read" or "run" "all the information from a page". You probably need to call webread() or something. Please attach your script (m-file) if you have one.
回答(1 个)
Sameer
2024-2-15
Hi,
From my understanding, you're looking to retrieve data from a web service, and you've shared a JSON snippet that contains a URL under the ‘datos’ key, which seems to be the endpoint where the data can be accessed.
To retrieve data from a web service using MATLAB, you can utilize the "webread" function.
Please refer to the documentation links below:
Below is an example MATLAB code to accomplish this:
% Defined the URL from the "datos" field
datosUrl = 'https://opendata.aemet.es/opendata/sh/79adac19';
% If an API key is required, setup using weboptions
% Replace 'your_api_key_here' with the actual API key if needed
options = weboptions('HeaderFields', {'api_key', 'your_api_key_here'});
%If an API key is not required, you can simplify the options setup
%options = weboptions();
% Retrieve the data from the URL
try
% Use webread to get the data
data = webread(datosUrl, options);
% Display or process the data
disp(data);
catch ME
% Handle any errors that may occur
fprintf('Error retrieving data: %s\n', ME.message);
end
I hope this helps!
Sameer
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Web Services 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!