|
-
Sep 9th, 2008, 01:26 PM
#1
Thread Starter
Junior Member
[RESOLVED] Parsing Info from HTML tables
-
Sep 9th, 2008, 08:49 PM
#2
Re: Parsing Info from HTML tables
This will work with the html you provided
Code:
Option Explicit
Private Sub Form_Load()
Dim fso As FileSystemObject
Dim ts As TextStream
Dim strHtml As String
Dim strSearch As String
Dim strRows() As String
Dim strTD() As String
'load the file
Set fso = New FileSystemObject
Set ts = fso.OpenTextFile("c:\score.txt")
'extract all the html
strHtml = ts.ReadAll
'split the html on each row
strSearch = "<tr class=""text"">"
strRows = Split(strHtml, strSearch)
'Since you only the last row then pull it from the html
strHtml = strRows(UBound(strRows))
'Separate the TD tags
strSearch = "</td>"
strTD = Split(strHtml, strSearch)
'Display your values
Text1.Text = GetValue(strTD(0))
Text2.Text = GetValue(strTD(2))
ts.Close
Set ts = Nothing
Set fso = Nothing
End Sub
Private Function GetValue(ByVal strLine As String) As String
Dim strTemp As String
Dim intPos As Integer
'cleanup the input
strTemp = Replace(strLine, vbCrLf, "")
strTemp = Trim(strTemp)
'Remove any tags before the value
Do While Left(strTemp, 1) = "<"
intPos = InStr(strTemp, ">") + 1
strTemp = Mid(strTemp, intPos)
Loop
'Remove any tags after the value
intPos = InStr(strTemp, "<")
If intPos > 0 Then
strTemp = Left(strTemp, intPos - 1)
End If
GetValue = strTemp
End Function
-
Sep 11th, 2008, 07:44 PM
#3
Thread Starter
Junior Member
Re: Parsing Info from HTML tables
Hey MarkT
Thank you so much for helping me out. The code that you gave worked smoothly.
Simon
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|