|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
以下程式可擷取10月2日至10月31日的資料。
Sub 財富財經日曆數據()
Dim JsStr As String
Dim Js As String
Dim tmpStr As String
Dim i As Integer
Dim nPage As Byte
Dim nRow As Integer
ThisWorkbook.ActiveSheet.Cells.Clear
JsStr = "http://data.eastmoney.com/DataCenter_V3/cjrl/getData.ashx?&pagesize=50&page=1&js=var o&sortRule=1&sortType=ConferenceDate&startDateTime=2017-10-02&endDateTime=2017-10-31&Type=all&rt=50237291"
With CreateObject("WinHttp.WinHttpRequest.5.1")
.Open "GET", JsStr, False
.setrequestheader "Referer", "http://data.eastmoney.com/cjrl/default.html"
.send
JsStr = .responsetext
End With
tmpStr = JsStr & ";"
With CreateObject("MSScriptControl.ScriptControl")
.Language = "JScript"
.addcode tmpStr
nPage = .Eval("o.pages")
End With
nRow = 0
For i = 1 To nPage
JsStr = "http://data.eastmoney.com/DataCenter_V3/cjrl/getData.ashx?&pagesize=50&page=" & i & "&js=var o&sortRule=1&sortType=ConferenceDate&startDateTime=2017-10-02&endDateTime=2017-10-31&Type=all&rt=50237291"
With CreateObject("WinHttp.WinHttpRequest.5.1")
.Open "GET", JsStr, False
.setrequestheader "Referer", "http://data.eastmoney.com/cjrl/default.html"
.send
JsStr = .responsetext
End With
Js = "var r,k,row=c=1,d={};for(r in j){row++;for(k in j[r]){if(!d[k]){d[k]=c++;rng(1,d[k])=k;}rng(row,d[k])= j[r][k];}}"
Js = "j=" & Split(Split(JsStr, "data"":")(1), "]")(0) & "]" & ";" & Js
With CreateObject("MSScriptControl.ScriptControl")
.Language = "JScript"
.AddObject "rng", ThisWorkbook.ActiveSheet.Range("A" & nRow + 1)
.Eval (Js)
End With
If i <> 1 Then
With ThisWorkbook.ActiveSheet
.Rows(nRow + 1).Delete
nRow = .Range("A65536").End(xlUp).Row
End With
Else
nRow = ThisWorkbook.ActiveSheet.Range("A65536").End(xlUp).Row
End If
Next i
ThisWorkbook.ActiveSheet.Columns("A:R").AutoFit
End Sub |
|