View Single Post
  #1  
Old 11-08-2009, 11:28 PM
Blupig's Avatar
Blupig (Offline)
wat i don't even
 
Join Date: Aug 2007
Posts: 159
Blupig is an unknown quantity at this point
Default [VB.net][TUT] Grabbing a page's source code

1. Start a new project (doesn't matter what it is as long as it has either a startup form or a sub main())

2. Import the System.Net library:
Imports System.Net
^That code goes above all of your other code

3. Initialize a new webclient (this can be global or for a single sub/function, it doesn't matter)

4. Declare a string to store the source code in

5. Using any event you like (clicking a button, pushing a key, etc.), call on the DownloadString class of the webclient:
strString = wcWebClient.DownloadString("http://www.website.com/")
strString is the name of your string you declared earlier, wcWebClient is the name of the webclient you created.

You're now done.

Example code:

Imports System.Net
Public Class Form1

    Dim wcWebClient As New Webclient
    Dim strString As String

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

               strString = wcWebClient.DownloadString("http://www.google.ca/")

    End Sub
End Class
How is this useful at all? Well with the source from a webpage you can parse information. This is what Runescape clients use for example to parse through online databases.

Last edited by Blupig; 11-08-2009 at 11:29 PM..
Reply With Quote