read Information from a web

조회 수: 2 (최근 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 CenterFile Exchange에서 Web Services에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by