Mine data from webbrowser to textboxes

Turbols1

Member
Joined
Jan 25, 2010
Messages
13
Programming Experience
1-3
Please forgive me if this is not the proper venue for my question. I have been stuck trying to search for an answer to this for a day or two. I am using VS2008.

I am new to using webbrowser, and am trying to mine data from a webpage and use that data to populate textboxes (which will later be used to fill out and print a form).

For example, if the HTML source code looks like this...
VB.NET:
<html>
<head>
<title>myGulf.com: Customer Login</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="gsstyles.css" rel="stylesheet" type="text/css">
</head>
...how would I mine or parse "myGulf.com" and place it into a textbox? I have tried using regex, but cannot get the code to work by viewing incomplete code snipets from other posts (I dont yet have enough understanding of regex).

Thanks in advance for any help, this forum has already proven an excellent source of information.
 
The source is already loaded and parsed with the WebBrowser. The title you can get from DocumentTitle property, the whole document tree from Document property (follow the link and read about the HtmlDocument class also).

To get the part of the title you can use regular String methods, for example where 'title' refers to the document title string:
VB.NET:
title = title.Split(":"c)(0)
 
Thanks for the reply, I have been reading up on the links you provided. This is what I have now...the long string is the name of the instance I want the value for.
VB.NET:
Private Sub ImportCLSnetDataToolStripMenuItem1_Click(ByVal sender As  _
System.Object, ByVal e As System.EventArgs) Handles ImportCLSnetDataToolStripMenuItem1.Click
        Dim document As System.Windows.Forms.HtmlDocument = WebBrowser1.Document
        Dim instance As WebBrowser
        Dim value As HtmlDocument
        value = instance.Document
        If document IsNot Nothing And document.All("ctl00$cM$ccPartRequest$TCSPartSearchIPS$InventoryPartRadComboBox_Input")_
 IsNot Nothing And String.IsNullOrEmpty(document.All("ctl00$cM$ccPartRequest$TCSPartSearchIPS$InventoryPartRadComboBox_Input").GetAttribute("value")) Then
            MsgBox("Could not find the installed part number.")
        Else
            TextBox20.Text = value
        End If

    End Sub
I am now getting a warning: "Variable 'instance' is used before it has been assigned a value."

And an error: "Value of type 'System.Windows.Forms.HtmlDocument' cannot be converted to 'String'."
 
Let's take things a bit slower, one thing at a time:
VB.NET:
Dim document As System.Windows.Forms.HtmlDocument = WebBrowser1.Document

If document Is Nothing Then
    MsgBox("No document is loaded.")
    Return
End If

Dim controlId As String = "ctl00$cM$ccPartRequest$TCSPartSearchIPS$InventoryPartRadComboBox_Input"
Dim element As HtmlElement = document.GetElementById(controlId)
If element Is Nothing Then
    MsgBox("Could not find control id.")
    Return
End If

Dim value As String = element.GetAttribute("value")
If String.IsNullOrEmpty(value) Then
    MsgBox("Could not find the installed part number.")
Else
    TextBox1.Text = value
End If
 
Parse using webbrowser

Im sure this is an easy one, Im just not very proficient yet...how would you parse only the M09-1900 from this html since there is no "value" property to identify it? The source code is already loaded into a textbox in the form. Thanks in advance for the help!

VB.NET:
<span id="ctl00_cM_ccPartRequest_DocumentNumberLabel">M09-1900 [11/23/2009 16:01 Z]</span>

The code below is what I tried and it doesnt work...
VB.NET:
'PO On Textbox7
        Dim POId As String = "ctl00_cM_ccPartRequest_DocumentNumberLabel"
        Dim PO As HtmlElement = document.GetElementById(POId)
        If PO Is Nothing Then
            MsgBox("Please use the browser to navigate to a valid CLS.net transaction, then browse to the ""Ship Core"" step before attempting to import data.")
            Return
        End If
        Dim POvalue As String = PO.GetAttribute("value")
        TextBox7.Text = POvalue
 
Back
Top