Documentation

urlread

Download URL content to character vector (not recommended)

urlreadis not recommended. Usewebreadorwebwriteinstead.

Syntax

str = urlread(URL)
str = urlread(URL,Name,Value)
[str,status] = urlread(___)

Description

example

str= urlread(URL)downloads the HTML web content from the specifiedURLinto the character vectorstr.urlreaddoes not retrieve hyperlink targets and images.

example

str= urlread(URL,Name,Value)uses additional options specified by one or moreName,Valuepair arguments.

[str,status] = urlread(___)suppresses the display of error messages, using any of the input arguments in the previous syntaxes. When the operation is successful,statusis1. Otherwise,statusis0

Examples

collapse all

Download the HTML for the page on the MATLAB® Central File Exchange that lists submissions related tourlread.

fullURL = ['//www.tianjin-qmedu.com/matlabcentral/fileexchange'...'?term=urlread']; str = urlread(fullURL);

urlreadreads from the specified URL and downloads the HTML content to the character vectorstr.

Download the HTML for the page on the MATLAB® Central File Exchange that lists submissions related tourlread.

URL='//www.tianjin-qmedu.com/matlabcentral/fileexchange'; str = urlread(URL,'Get',{'term','urlread'});

urlreadreads from//www.tianjin-qmedu.com/matlabcentral/fileexchange/?term=urlreadand downloads the HTML content to the character vectorstr.

Download content from a page on the MATLAB® Central File Exchange as in the first example, and specify a timeout duration of 5 seconds.

fullURL = ['//www.tianjin-qmedu.com/matlabcentral/fileexchange'...'?term=urlread']; str = urlread(fullURL,'Timeout',5);

Input Arguments

collapse all

Content location, specified as a character vector. Include the transfer protocol, such ashttp,ftp, or文件.

Example:'//www.tianjin-qmedu.com/matlabcentral'

Name-Value Pair Arguments

Specify optional comma-separated pairs ofName,Valuearguments.Nameis the argument name andValueis the corresponding value.Namemust appear inside single quotes (' '). You can specify several name and value pair arguments in any order asName1,Value1,...,NameN,ValueN.

Example:'Timeout',10,'Charset','UTF-8'specifies thaturlreadshould time out after 10 seconds, and the character encoding of the file is UTF-8.

collapse all

Parameters of the data to send to the web form using the GET method, specified as the comma-separated pair consisting of'get'and a cell array of paired parameter names and values. The supported parameters depend upon the URL.

'Get'includes the data in the URL, separated by?and&characters.

Example:'Get',{'term','urlread'}

Parameters of the data to send to the web form using the POST method, specified as the comma-separated pair consisting of'post'and a cell array of paired parameter names and values. The supported parameters depend upon the URL.

'Post'submits the data as part of the request headers, not explicitly in the URL.

Character encoding, specified as the comma-separated pair consisting of'Charset'and a character vector. If you do not specifyCharset, the function attempts to determine the character encoding from the headers of the file. If the character encoding cannot be determined,Charsetdefaults to the native encoding for the file protocol, and UTF-8 for all other protocols.

Example:'Charset','ISO-8859-1'

Timeout duration in seconds, specified as the comma-separated pair consisting of'Timeout'and a scalar. The timeout duration determines when the function errors rather than continues to wait for the server to respond or send data.

Example:'Timeout',10

Client user agent identification, specified as the comma-separated pair consisting of'UserAgent'and a character vector.

Example:'UserAgent','MATLAB R2012b'

HTTP authentication mechanism, specified as the comma-separated pair consisting of'Authentication'and a character vector. Currently, only the value'Basic'is supported.'Authentication','Basic'specifies basic authentication.

If you include theAuthenticationargument, you must also include theUsernameandPasswordarguments.

User identifier, specified as the comma-separated pair consisting of'Username'and a character vector. If you include theUsernameargument, you must also include thePasswordandAuthenticationarguments.

Example:'Username','myName'

User authentication password, specified as the comma-separated pair consisting of'Password'and a character vector. If you include thePasswordargument, you must also include theUsernameandAuthenticationarguments.

Example:'Password','myPassword123'

Output Arguments

collapse all

Contents of the file at the specified URL, returned as a character vector. For example, if the URL corresponds to an HTML page,strcontains the text and markup in the HTML file. If the URL corresponds to a binary file,stris not readable.

Download status, returned as either1or0. When the download is successful,statusis1. Otherwise,statusis0.

Tips

  • urlreadsaves web content to a character vector. To save content to a file, useurlwrite.

  • urlreadandurlwritecan download content from FTP sites. Alternatively, use theftpfunction to connect to an FTP server and themgetfunction to download a file.

Introduced before R2006a

Was this topic helpful?