Skip to Main Content Skip to Search
Product Documentation

urlwrite - Download URL content and save to file

Syntax

urlwrite(URL,filename)
urlwrite(URL,filename,method,{Name,Value})
[filestr,status] = urlwrite(URL,filename)
[filestr,status] = urlwrite(URL,filename,method,{Name,Value})

Description

urlwrite(URL,filename) reads Web content at the specified URL and saves it to the file specified by filename.

urlwrite(URL,filename,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.

[filestr,status] = urlwrite(URL,filename) stores the file path in variable filestr, and suppresses the display of error messages. When the operation is successful, status is 1. Otherwise, status is 0.

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

Input Arguments

URL

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

filename

String that specifies the name of the file to store the Web content. If you do not specify the path for filename, the urlwrite function saves the file in the current folder.

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

filestr

String containing the path of the file.

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 urlwrite. Save the results to samples.html in the current directory:

urlwrite(...
    'http://www.mathworks.com/matlabcentral/fileexchange',...
    'samples.html', ...
    'get', ...
    {'term','urlwrite'});

Alternatively, specify the complete URL:

fullURL = ['http://www.mathworks.com/matlabcentral/fileexchange' ...
           '?term=urlwrite'];
urlwrite(fullURL,'samples.html');

View the file:

web('samples.html')

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 | urlread | web

How To

  


» Learn more
» Download free kit
» Get trial software

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