Download Web Page and Files ®

MATLAB  provides two functions for reading content from RESTful web services: webread andwebsave. 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 a Web page's 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. Note   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 thewebread 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,http://www.mathworks.com/matlabcentral/fileexchange/. It assigns the results to a character array, fullList: filex = 'http://www.mathworks.com/matlabcentral/fileexchange/'; fullList = webread(filex);

Retrieve a list of only those files uploaded to the File Exchange within the past 7 days that contain the word Simulink®. Set duration and term as parameters that webread passes to the Web page. filex = 'http://www.mathworks.com/matlabcentral/fileexchange/'; 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 = 'http://www.mathworks.com/matlabcentral/fileexchange/'; % Save the Web content to a file. recent = websave('contains_simulink.html',filex, ...     'duration',7,'term','simulink');

MATLAB saves the Web page as contains_simulink.html. The output argument recentcontains the full path to contains_simulink.html. Call the web function to displaycontains_simulink.html in a browser. web(recent)

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

Download Web Page and Files - MATLAB & Simulink.pdf

Download Web Page and Files - MATLAB & Simulink.pdf. Download Web Page and Files - MATLAB & Simulink.pdf. Open. Extract. Open with. Sign In.

86KB Sizes 1 Downloads 238 Views

Recommend Documents

No documents