从中国银行网站采集银行汇率
时 间:2017-12-08 11:23:29
作 者:大海 ID:42003 城市:深圳
摘 要:从指定网页采集数据的源代码示例。
正 文:
因为工作的原因,需要实时获取当日的银行汇率,以前一直是通过打开网页复制获得数据,现在用access数据库制做了一个从中国银行网站上采集汇率的示例,感觉方便了很多。本示例的下载请点击屏幕左下角的“阅讯原文”,供大家参考!
代 码:
Sub 汇率采集()
Dim url As String
Dim hmlFile As Object
Dim arr() As Variant
Dim r As Variant
Dim I As Integer
Dim j As Integer
Dim m As Integer
Dim SQL1 As String
Dim rst1 As New ADODB.Recordset
CurrentDb.Execute "delete * from 中国银行汇率"
url = "http://www.boc.cn/sourcedb/whpj"
With CreateObject("microsoft.xmlhttp")
.Open "GET", url, False
.Send
Do Until .ReadyState = 4
DoEvents
Loop
Set hmlFile = CreateObject("htmlfile")
hmlFile.body.innerhtml = .responsetext
End With
Set r = hmlFile.ALL.tags("table")(1).Rows
ReDim arr(r.Length - 1, r(0).Cells.Length - 1)
For I = 0 To UBound(arr)
For j = 0 To UBound(arr, 2)
arr(I, j) = r(I).Cells(j).innertext
Next
Next
SQL1 = "select * from 中国银行汇率"
rst1.Open SQL1, CurrentProject.Connection, adOpenKeyset, adLockOptimistic
On Error Resume Next
For m = 1 To UBound(arr)
rst1.AddNew
rst1!货币名称 = arr(m, 0)
If arr(m, 1) <> "" Then rst1!现汇买入价 = arr(m, 1) Else rst1!现汇买入价 = 0
If arr(m, 2) <> "" Then rst1!现汇卖出价 = arr(m, 2) Else rst1!现汇卖出价 = 0
rst1!现钞买入价 = arr(m, 3)
rst1!中行折算价 = arr(m, 4)
rst1!现钞卖出价 = arr(m, 5)
rst1!发布日期 = arr(m, 6)
rst1!发布时间 = arr(m, 7)
rst1.Update
Next
Set hmlFile = Nothing
Set rst1 = Nothing
End Sub
附 件:
图 示:
Access软件网QQ交流群 (群号:54525238) Access源码网店
常见问答:
技术分类:
源码示例
- 【源码QQ群号19834647...(12.17)
- 【Access选项卡示例】Ac...(09.09)
- 【Access源码示例】按输入...(09.02)
- 【Access日期区间段查询】...(08.29)
- 【Access日期区间段查询】...(08.27)
- Access怎样才能实现日期时...(08.21)
- 【Access定时打开查询】A...(08.19)
- Access生成固定数量的记录...(08.13)
- Access怎样才能实现日期时...(08.12)
- Access利用导航窗体控件对...(08.03)
学习心得
最新文章
- Access表中的字段名、字段标题...(09.19)
- Access快速开发平台--更改“...(09.18)
- 【中秋及国庆优惠】Access培训...(09.15)
- Access如何将日期型的数值转换...(09.14)
- 英文输入法输入数据中存在单引号引起...(09.11)
- 【Access选项卡示例】Acce...(09.09)
- 让Access光标停留在指定的控件...(09.07)
- 关于Access查询条件里使用通配...(09.06)
- Access报表偷懒制作法--Ac...(09.05)
- Access快速开发平台--窗体数...(09.04)