Read data from the built-in MATLAB web browser

9 vues (au cours des 30 derniers jours)
John
John le 19 Mar 2017
I'm trying to read data from a website (using webread) that doesn't use basic authentication to log me in. I've decided maybe the easier way would be to open the page using the built-in MATLAB web browser (see below), and once logged in, read the data from the browser itself. Is this possible?
[stat,h,url]=web(url);

Réponses (1)

Madheswaran
Madheswaran le 9 Jan 2025
Hi John,
Apart from using the built-in web browser as described in the answer link you posted, you can do the following. If your API is using cookies for authentication, you can capture those cookies and use them with 'webread'
  1. First, log into your website using a regular browser (Chrome/Firefox)
  2. Open Developer Tools (F12)
  3. Go to the Network tab
  4. Look for any request after logging in
  5. Find the 'Cookie' header in the request headers
  6. Use this cookie in MATLAB 'webread' command
options = weboptions('HeaderFields', {'Cookie', 'your_captured_cookie_here'});
try
data = webread('your_url_here', options);
disp(data);
catch ME
fprintf('Error: %s\n', ME.message);
end
Refer to the following MathWorks documentation for more information:
  1. webread - https://mathworks.com/help/matlab/ref/webread.html
  2. weboptions - https://mathworks.com/help/matlab/ref/weboptions.html#d126e1977106
Hope this helps!

Community Treasure Hunt

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

Start Hunting!

Translated by