MATLAB Examples

Read URL Using

This example shows how to display HTML text from the first paragraph on the website.


Construct URL Object

Call a constructor to create object url pointing to the MathWorks website.

url ='');

Open Connection to URL

Call the openStream method to establish a connection with the website. The method creates an InputStream object is for reading bytes from the site.

is = openStream(url);

Set Up Buffered Stream Reader

Create a buffered stream reader isr for reading characters using the constructor. Create a buffered reader object br for efficient reading of characters, arrays, and lines.

isr =;
br =;

Read Lines of Text

Read lines of HTML text from the website which are within the first paragraph tag '<p>'. The BufferedReader method readLine reads a line of text which is terminated by a carriage return and/or line feed character.

p1 = java.lang.String('<p>');
p2 = java.lang.String('</p>');
s = readLine(br);
while ~(s.startsWith(p1))
    s = readLine(br);

Display Text

<i>Accelerating the pace of engineering and science</i>