Skip to Main Content Skip to Search
Product Documentation

urlread - Download URL content to MATLAB string

Syntax

str = urlread(URL)
str = urlread(URL,method,{Name,Value})
[str,status] = urlread(URL)
[str,status] = urlread(URL,method,{Name,Value})

Description

str = urlread(URL) downloads the Web content from the specified URL into the string str.

str = urlread(URL,method,{Name,Value}) passes data to the server using a method of 'get' or 'post'. Specify the data to send with one or more Name,Value pair arguments.

[str,status] = urlread(URL) suppresses the display of error messages. When the operation is successful, status is 1. Otherwise, status is 0.

[str,status] = urlread(URL,method,{Name,Value}) passes data to the server and suppresses the display of error messages.

Tips

To save Web content to a file rather than a string, use urlwrite.

Input Arguments

URL

String that specifies the location of Web content. Include the transfer protocol, such as http, ftp, or file.

method

String that specifies how the Web form expects to receive data:

'get'

Include the data in the URL, separated by ? and & characters.

'post'

Submit the data as part of the request, not explicitly in the URL.

Name-Value Pair Arguments

Cell array of comma-separated pairs of Name, Value arguments, where Name is the field name and Value is the corresponding value. Required when you specify a method.

The supported values for Name and Value depend upon the Web form. You can specify several name-value pair arguments as Name1,Value1,…,NameN,ValueN.

Output Arguments

str

String containing the contents of the file at the specified URL. For example, if the URL corresponds to an HTML page, str contains the text and markup in the HTML file. If the URL corresponds to a binary file, str is not readable.

status

Number of class double that indicates whether the download is successful. When successful, status is 1. Otherwise, status is 0.

Examples

Download the HTML for the page on the MATLAB Central File Exchange that lists submissions related to urlread:

exPage = urlread(...
     'http://www.mathworks.com/matlabcentral/fileexchange',...
     'get', ...
     {'term','urlread'});

Alternatively, specify the complete URL:

fullURL = ['http://www.mathworks.com/matlabcentral/fileexchange' ...
           '?term=urlread'];
exPage = urlread(fullURL);

Alternatives

urlread and urlwrite can download content from FTP sites. Alternatively, use the ftp function to connect to an FTP server and the mget function to download a file.

See Also

ftp | urlwrite | web

How To

  


Free MATLAB Interactive Kit

Explore how to use MATLAB to make advancements in engineering and science.


Download free kit

Trials Available

Try the latest version of MATLAB and other MathWorks products.


Get trial software
 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS