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