Saturday, November 15, 2008

How to quickly get the HTML source of an unsecured web page in Visual Basic .Net

There are a LOT of useful applications that can be built on the premise of just retrieving the raw HTML of a publicly available web page and then parsing and analyzing the page contents. That should not be a surprise to anyone, but what may be surprising is just how simple it is to do in .Net.

Here is an example that shows just how easy it is:

Dim myURI as new System.URI("")

Dim myHTML as string = GetURIText(myURI)

Protected Function GetURIText(ByVal myURI As System.Uri) As String

Dim result As String = String.Empty

If Not IsNothing(myURI) Then

Dim wb As New System.Net.WebClient

result = wb.DownloadString(myURI)

End If

Return result

End Function

Hope that helps.

Joe Kunk
Okemos, MI

No comments: