Need to read data from HTML table into an array

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ducky801

    #1

    Need to read data from HTML table into an array

    Using VB 2005 express:

    I am using the webbrowser control to manipulate a website. i need to
    get the contents of a named table off of one of the pages and put into
    an array. how can i do this? i have been tinkering with the
    mshtml.htmltabl e object but don't quite understand how to use it
    correctly. how do assign any value to it? do i pass the HTML as a
    string? (because that doesn't seem to be working). PLEASE HELP ME.
    I've been stumped on this all day

    AR

  • Michael M.

    #2
    Re: Need to read data from HTML table into an array

    Ducky,

    I havent used the webbrowser control before but, you could:

    Parse the text as string using the tags as dilemeters and using the Split()
    command that returns an array diveded by dilimeters of your choosing
    <tr>
    <td>Data</td><td>Dat2</td>
    <tr/>

    Or if you can access the Document Object Model then you could use .InnerText
    or whatever to retrieve the element contents only.

    Actualy ... I got intrested in this (I had never used Web browser control so
    loaded one in to look) being a former web developer so wrote this code; let
    me know if it's what you wanted

    it is stll kinda using the Document Object Model as mentioned before though!



    Public Class Form1

    Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
    System.EventArg s) Handles MyBase.Load

    '* I put the code into the document, but would be same if loaded via HTTP I
    think

    Me.WebBrowser1. DocumentText = "<html><Title>T est</Title><body><ta ble
    border='1'><tr> <td name='td'>td1 a</td><td>td1 b</td></tr><tr><td>td1
    b</td><td>td2 b</td></tr></table></body></html>"



    End Sub

    Private Sub WebBrowser1_Doc umentCompleted( ByVal sender As System.Object,
    ByVal e As System.Windows. Forms.WebBrowse rDocumentComple tedEventArgs)
    Handles WebBrowser1.Doc umentCompleted

    Dim strArHtmlTableD ata() As String

    Dim intIndex As Integer = 0

    For Each TblElement As System.Windows. Forms.HtmlEleme nt In
    Me.WebBrowser1. Document.All

    If UCase(TblElemen t.TagName.ToStr ing).Contains(" TD") Then

    strArHtmlTableD ata(intIndex) = TblElement.Inne rText

    'MessageBox.Sho w(TblElement.In nerText)



    End If

    intIndex += 1

    Next

    End Sub

    End Class

    Regards,

    Mike.

    "ducky801" <areese801@gmai l.comwrote in message
    news:1168023625 .277792.290240@ v33g2000cwv.goo glegroups.com.. .
    Using VB 2005 express:
    >
    I am using the webbrowser control to manipulate a website. i need to
    get the contents of a named table off of one of the pages and put into
    an array. how can i do this? i have been tinkering with the
    mshtml.htmltabl e object but don't quite understand how to use it
    correctly. how do assign any value to it? do i pass the HTML as a
    string? (because that doesn't seem to be working). PLEASE HELP ME.
    I've been stumped on this all day
    >
    AR
    >

    Comment

    Working...