Foxtable(狐表)用户栏目专家坐堂 → 网页表格数据保存到狐表表中


  共有3326人关注过本帖树形打印复制链接

主题:网页表格数据保存到狐表表中

帅哥哟,离线,有人找我吗?
有点甜
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2015/2/8 9:12:00 [显示全部帖子]

Dim web As System.Windows.Forms.WebBrowser = e.Form.Controls("WebBrowser1").basecontrol
'web.Navigate("http://www.tianqihoubao.com/weather/top/liuzhou.html")
'Do Until web.ReadyState = 4
'Application.DoEvents
'Loop
'
'
'取数据
Dim Cols() As String = { "日期","最高温度","最低温度" }

Dim elems As object = web.Document.GetElementById("content").GetElementsByTagName("tr")
Dim m As Integer = -1
For Each elem As object In elems
    Dim i As Integer = -1
    Dim r As DataRow
    m = m + 1
    Dim tdelems As object =  elem.GetElementsByTagName("td")
    If m > 1 Then  '因为网页的表格有标题,如果不判断,就会增加出一个空行
        Dim d As Date = IIF(tdelems(1).Innertext.Contains("星期"),tdelems(1).Innertext.Substring(0,10),tdelems(1).Innertext)
        Dim fdr As DataRow = DataTables("历史温度").Find("日期 = #" & d & "#")
        If fdr Is Nothing Then
            r = DataTables("历史温度").AddNew
        Else
            r = fdr
        End If
    End If
   
   
    For Each tdelem As object In tdelems
        i = i + 1
        If r IsNot Nothing Then
            Select Case i
                Case 1
                    r("日期") = IIF(tdelem.Innertext.Contains("星期"),tdelem.Innertext.Substring(0,10),tdelem.Innertext)
                Case 4
                    r("最高温度") = tdelem.Innertext.trim("℃")
                Case 7
                    r("最低温度") = tdelem.Innertext.trim("℃")
            End Select
        End If
    Next
Next
Tables("历史温度").save


 回到顶部