此主题相关图片如下:foxtable获取网页数据.png
On Error Goto Qt
Dim ObjIE As Object, Dom As Object, r As Object, i As Long, j As Integer
ObjIE = CreateObject("Internetexplorer.Application")
StatusBar.Message1 = "正在查询网页信息,可能耗时较久,请耐心等待..."
StatusBar.Refresh
With ObjIE
.Navigate("http://ball365.net/newo/mpk.html?ct=1317477534001") '网址
Do Until .ReadyState = 4
Application.DoEvents
Loop
Dom = .Document
End With
r = Dom.All.tags("table")(35).Rows
Dim TblName As String = Inputbox("请输入要创建的临时查询表的名称:","输入临时表名","查询结果")
If TblName = "" Then Goto Qt : Return Nothing
StatusBar.Message1 = "正在动态修改表结构..."
StatusBar.Refresh
Dim TblBld As New DataTableBuilder(TblName )
For i = 0 To r(0).Cells.Length
TblBld.AddDef("列" & i + 1,Gettype(String),250)
Next
TblBld.Build
Dim Tbl As Table = Tables(TblName )
With Tbl
If r.Length > .Rows.Count Then .Rows.AddNew(r.Length - .Rows.Count)
Dim ColName As String
For i = 0 To r.Length - 1
For j = 0 To r(i).Cells.Length - 1
ColName = .Cols(j).Name
.Rows(i)(ColName) = r(i).Cells(j).innerText
Next
Next
End With
MainTable = Tbl
StatusBar.Message1 = "数据查询完成..."
StatusBar.Refresh
Msgbox("ok")
Qt:
If Err.Number > 0 Then Msgbox(Err.Number & vbCrlf & Err.Description)
StatusBar.Reset
ObjIE.Quit
ObjIE = Nothing
Dom = Nothing
r = Nothing