Retrieve a Single Piece of Information from a Web Page

Problem

You want to extract a single piece of information from a Web page.

Solution

Use the WebResponse class to retrieve the stream, copy it to a string, and use a regular expression.

Discussion

You can extract information from a Web stream in several ways. You could read through the stream, use methods of the String class such as IndexOf, or apply a regular expression. The latter of these—using a regular expression—is the most flexible and powerful.

The first step is to create a regular expression that filters out the information you need. recipe Parse a String Into Words provides several examples and a reference to basic regular expression syntax. For example, most Web pages include a text title ...

Get Microsoft® Visual Basic® .NET Programmer's Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.