Documentation Center

  • Trial Software
  • Product Updates

Downloading Web Content and Files

MATLAB® provides two functions for downloading Web pages and files using HTTP: urlread and urlwrite. With the urlread function, you can read and save the contents of a Web page to a string variable in the MATLAB workspace. With the urlwrite function, you can save a Web page's content to a file.

Because it creates a string variable in the workspace, the urlread function is useful for working with the contents of Web pages in MATLAB. The urlwrite function is useful for saving Web pages to a local folder.

    Note   When using urlread, 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 urlread and urlwrite functions let you use HTTP post and get methods. For more information, see the urlread and urlwrite reference pages.

Example — Using the urlread 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 string variable, fullList:

filex = '';
fullList = urlread(filex);

To pass arguments, you can include them manually using the URL, or pass parameters using standard HTTP methods, including post and get.

For example, to pass arguments as part of the URL, and retrieve only the files uploaded to the Central File Exchange within the past 7 days that contain the word Simulink:

filex = sprintf('%s%s',...
recent = urlread(filex);

Alternatively, use the HTTP get method to query the list of files:

filex = '';
params = {'duration','7','term','simulink'};

recent = urlread(filex,'get',params);

For more information, see the urlread reference page.

Example — Using the urlwrite 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 = '';
params = {'duration','7','term','simulink'};

% Save the Web content to a file.

MATLAB saves the Web page as contains_simulink.html.

Was this topic helpful?