Question Retrieving Information from a Web Page

Eleqtriq

New member
Joined
Jan 23, 2010
Messages
4
Programming Experience
1-3
Hello and thanks for reading. I am having a bit of trouble figuring out how to collect a piece of information from a web page. Here is the web page I want to retrieve the information from:

RuneScape - The Number 1 Free Multiplayer Game

I would like to retrieve the first "Price" of the item and collect the price every time I execute the code. I understand how to retrieve the source code of the webpage and split strings but how would I retrieve that price? Thanks.
 
The WebBrowser control is an excellent tool for this, because it has the whole document tree parsed and available for use from Document property. The control doesn't have to be Visible in form to operate. Here's a code sample that looks up the information when document has finished loading:
VB.NET:
Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
    If Me.WebBrowser1.ReadyState = WebBrowserReadyState.Complete Then
        Dim table As HtmlElement = Me.WebBrowser1.Document.GetElementById("search_results_table")
        For Each row As HtmlElement In table.GetElementsByTagName("tr")
            Dim cells As HtmlElementCollection = row.GetElementsByTagName("td")
            If cells.Count > 0 Then
                Dim name As String = cells(1).InnerText
                Dim price As String = cells(2).InnerText
                Debug.WriteLine(name & " " & price)
            End If
        Next
    End If
End Sub
Since you don't know this control, here's how to navigate it:
VB.NET:
Me.WebBrowser1.Navigate("http://itemdb-rs.runescape.com/results.ws?query=green+dragonhide")
 
Back
Top