I found a solution from a previous question https://www.mathworks.com/matlabcentral/answers/276583-how-can-i-save-the-content-of-the-matlab-web-browser-window-programmatically-not-the-same-as-webrea
Read data from the built-in MATLAB web browser
9 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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);
1 commentaire
Réponses (1)
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'
- First, log into your website using a regular browser (Chrome/Firefox)
- Open Developer Tools (F12)
- Go to the Network tab
- Look for any request after logging in
- Find the 'Cookie' header in the request headers
- 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:
- webread - https://mathworks.com/help/matlab/ref/webread.html
- weboptions - https://mathworks.com/help/matlab/ref/weboptions.html#d126e1977106
Hope this helps!
0 commentaires
Voir également
Catégories
En savoir plus sur Web Services dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!