필터 지우기
필터 지우기

How to retrieve data from a website?

조회 수: 68 (최근 30일)
ARGY B
ARGY B 2019년 8월 14일
댓글: the cyclist 2019년 8월 14일
I would like to retrieve data from a webasite, and store them in a matrix of two columns (or in two vectors).
I tried this:
url = ('http://matroos/direct/get_series.php?loc=hoekvanholland&source=observed&unit=waterlevel&tstart=201908140000&tstop=201908150000');
data = urlread(url);
But the result is not..satisfying!
Is there a smarter function to use instead of urlread?
(I have attached a pic of the website)
Thanx!
matlabquestion.PNG

채택된 답변

the cyclist
the cyclist 2019년 8월 14일
According to its documentation page, use of urlread is not recommended. It suggests using webread instead.
  댓글 수: 3
Rik
Rik 2019년 8월 14일
Your downloaded result is just a text file. There are probably line endings encoded in there (char 10 and/or 13), but you'll have to do the parsing yourself.
Also, I haven't yet seen a situation with http where urlread couldn't manage. For https it is generally better to use webread, but even then urlread will do fine. For situations like str2num I can understand why the use is discouraged, but for urlread and histc I can't really find the reason.
the cyclist
the cyclist 2019년 8월 14일
You might want to read the webread options section. The default is 'auto", which will try to determine the output type set by the server's API. I guess you could try one of the other options, if you know how the output is intended to be formatted (e.g. JSON).
It's probably just that the site returns plain text. In that case, you'll need to parse it yourself. There is an example of that here.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

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