Read data from the built-in MATLAB web browser

조회 수: 9 (최근 30일)
John
John 2017년 3월 19일
답변: Madheswaran 2025년 1월 9일
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개)

Madheswaran
Madheswaran 2025년 1월 9일
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!

카테고리

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