Acquiring a JSON from a webpage

3 views (last 30 days)
Tero on 30 Jul 2021
Commented: Yongjian Feng on 3 Aug 2021
Hi all,
I'd need to find a way to acquire a JSON file from a web portal. I can do it manually just by going to the site and save in JSON (see screenshot). However, I'd like to be able to do it directly from Matlab, but webread just returns the HTML code, not the data I'm looking for. I tried using the options:
options = weboptions('ContentType','json');
But it failed. Any idea is welcome

Answers (1)

Yongjian Feng
Yongjian Feng on 30 Jul 2021
Try this:
headers = {'Content-Type' 'application/json'; 'Accept' 'application/json'};
options = weboptions('HeaderFields',headers);
webread('', options)
Yongjian Feng
Yongjian Feng on 3 Aug 2021
I see. It seems like you just got back the html for the login page. In general, there shall be an API key for authentication. Or try to put your username/password into the headers as well.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by