Dim web As New System.Windows.Forms.WebBrowser() web.ScriptErrorsSuppressed = True web.Navigate("http://youjia.chemcp.com/YuanYouJiaGe.asp") Do Until web.ReadyState = 4 Application.DoEvents Loop Dim Cols() As String = { "名称","价格","涨跌额","涨跌幅","发布日期" } Dim ts = web.Document.GetElementsByTagName("table") If ts.count <= 5 Then msgbox("没查到,请检查你网络设置") Else Dim elems As object = web.Document.GetElementsByTagName("table")(5).GetElementsByTagName("tr") Dim t As Table = Tables("国际市场原油价格表") For i As Integer = 1 To elems.count-1 Dim tdelems As object = elems(i).GetElementsByTagName("td") Dim fdr As DataRow = t.DataTable.Find("名称 = '" & tdelems(0).Innertext & "' and 发布日期 = #" & tdelems(4).Innertext & "#") If fdr Is Nothing Then fdr = t.DataTable.AddNew End If For j As Integer = 0 To Cols.length-1 If t.Cols(j).IsNumeric Then fdr(Cols(j)) = val(tdelems(j).Innertext.replace("↓", "").replace("↑", "").replace("%", "")) Else fdr(Cols(j)) = tdelems(j).Innertext End If Next fdr("更新时间") = Date.Now Next t.save Tables("国际市场原油价格表").Sort = "发布日期 DESC" MessageBox.show("数据更新完毕!") End If
|