Need to read data from HTML table into an array

D

ducky801

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.htmltable 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
 
M

Michael M.

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(ByVal sender As System.Object, ByVal e As
System.EventArgs) 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>Test</Title><body><table
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_DocumentCompleted(ByVal sender As System.Object,
ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs)
Handles WebBrowser1.DocumentCompleted

Dim strArHtmlTableData() As String

Dim intIndex As Integer = 0

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

If UCase(TblElement.TagName.ToString).Contains("TD") Then

strArHtmlTableData(intIndex) = TblElement.InnerText

'MessageBox.Show(TblElement.InnerText)



End If

intIndex += 1

Next

End Sub

End Class

Regards,

Mike.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top