|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
农业银行日元汇率- Option Explicit
- Sub hk()
- Dim xml As New WinHttpRequest, str As String, reg As New RegExp, xml1 As String, html
- Dim i, j, m, n
- Dim ar, arr
- Dim VIEWSTATE As String, EVENTTARGET As String, EVENTARGUMENT, EVENTVALIDATION, ddr As String, date1, date2
- Dim tb
- xml1 = "http://app.abchina.com/rateinfo/RateHistorySearch.aspx"
- With xml
- .Open "GET", xml1, False
- .Send
- str = .ResponseText
- With reg
- .Global = True
- .MultiLine = True
- .Pattern = "\s"
- str = .Replace(str, "")
- .Pattern = "VIEWSTATE""value=""(.*?)"""
- VIEWSTATE = .Execute(str).Item(0).SubMatches(0)
- .Pattern = "DATION""value=""(.*?)"""
- Set ar = .Execute(str)
- EVENTTARGET = .Execute(str).Item(0).SubMatches(0)
- End With
- ddr = Sheet4.Range("a1")
- date1 = Sheet4.Range("b1")
- date2 = Sheet4.Range("c1")
- Set html = CreateObject("htmlfile")
- .Open "GET", xml1, False
- .Send "_VIEWSTATE=" & VIEWSTATE & "&_EVENTTARGET" & EVENTTARGET & "&ddr1=" & encodeURI(ddr) & "&datepicker1=" & date1 & "&datepicker2=" & date2 & "&btnSearch=" & encodeURI("搜索")
- str = .ResponseText
- Debug.Print str
- html.body.innerhtml = .ResponseText
- Set tb = html.all.tags("table")(1).Rows
- For i = 0 To tb.Length - 1
- For j = 1 To tb(i).Cells.Length - 1
- Sheet4.Cells(i + 3, j) = tb(i).Cells(j).innertext
- Next
- Next
- End With
- End Sub
- Function encodeURI(strTobecoded As String) As String
- With CreateObject("msscriptcontrol.scriptcontrol")
- .Language = "JavaScript"
- encodeURI = .Eval("encodeURIComponent('" & strTobecoded & "');")
- 'encodeURIComponent无法转换括号,所以再替换下括号
- encodeURI = Replace(Replace(encodeURI, "(", "%28"), ")", "%29")
- End With
- End Function
复制代码 |
|