Main Content

Download Web Page and Files

MATLAB® provides two functions for reading content from RESTful web services: webread and websave. With the webread function, you can read the contents of a web page to a character array in the MATLAB workspace. With the websave function, you can save web page content to a file.

Because it can create a character array in the workspace, the webread function is useful for working with the contents of web pages in MATLAB. The websave function is useful for saving web pages to a local folder.


When webread returns HTML as a character array, remember that only the HTML in that specific web page is retrieved. The hyperlink targets, images, and so on, are not retrieved.

If you need to pass parameters to a web page, the webread and websave functions let you define the parameters as Name, Value pair arguments. For more information, see the webread and websave reference pages.

Example — Use the webread Function

The following procedure demonstrates how to retrieve the contents of the web page listing the files submitted to the MATLAB Central™ File Exchange, It assigns the results to a character array, fullList:

filex = '';
fullList = webread(filex);

Retrieve a list of only those files uploaded to the File Exchange within the past seven days that contain the word Simulink®. Set duration and term as parameters that webread passes to the web page.

filex = '';
recent = webread(filex,'duration',7,'term','simulink');

Example — Use the websave Function

The following example builds on the procedure in the previous section, but saves the content to a file:

% Locate the list of files at the MATLAB Central File Exchange
% uploaded within the past 7 days, that contain "Simulink."
filex = '';

% Save the Web content to a file.
recent = websave('contains_simulink.html',filex, ...

MATLAB saves the web page as contains_simulink.html. The output argument recent contains the full path to contains_simulink.html. Call the web function to display contains_simulink.html in a browser.


This page has links to files uploaded to the MATLAB Central File Exchange.