read Information from a web

4 ビュー (過去 30 日間)
flashpode
flashpode 2021 年 9 月 28 日
回答済み: Sameer 2024 年 2 月 15 日
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
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.
flashpode
flashpode 2021 年 9 月 28 日
I just got this from the page and do not know how to do it to be able to read it

サインインしてコメントする。

回答 (1 件)

Sameer
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

カテゴリ

Help Center および File ExchangeWeb Services についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by