|
楼主 |
发表于 2014-10-15 23:12
|
显示全部楼层
本帖最后由 onlycxb 于 2014-10-16 08:51 编辑
复楼上,我是通过计算记录总数/每页20条记录得到总记录(代码中已经标注)。 网页数据地址为http://jiaoyi.sina.com.cn/api/js ... atio&ordertype=desc 其中,第一页 start为从0开始,第二页从20开始…………
分享6:
- Sub 新浪模拟交易()
- '网址:http://jiaoyi.sina.com.cn/jy/stock/ranking/
- '要求:按照格式将1-5页排民各自选手的子项数据导入excel
- '说明:以下代码仅演示提取"当前持昌数据表中的部分字段"
- Dim xml As New MSXML2.XMLHTTP, Js
- Dim Url$, st$, n%, i%, r%, j%, Total%, m%, k%
- Dim sht1 As Worksheet, sht2 As Worksheet, sht3 As Worksheet
- Dim arr(1 To 100000, 1 To 13), brr, crr
- Dim Sid As String
-
- '第一次读取,取总记录数Total
- Set sht1 = Sheets("当日持仓")
- sht1.UsedRange.Offset(1, 0).Clear
- Url = "http://jiaoyi.sina.com.cn/api/jsonp.php/Johansen=johansen062308384298872741413371443299/Ranking_Service.getRate?cid=10000&num=20&start=0&orderby=profit_ratio&ordertype=desc&qjson="
- With xml
- .Open "GET", Url, False
- .send
- st = Split(Split(.responseText, "johansen062308384298872741413371443299((")(1), "))")(0)
- End With
- Set Js = CreateObject("scriptcontrol")
- Js.Language = "jscript"
- Js.AddCode ("dy=" & st)
- Total = Js.Eval("dy.total") '37楼,这里取得记录数
-
- '利用总记录数进行循环,每页20条记录
- For i = 0 To 40 Step 20 '为提高测试速度,这里暂取40(两页),实际可用Total代替40
- Url = "http://jiaoyi.sina.com.cn/api/jsonp.php/Johansen=johansen062308384298872741413371443299/Ranking_Service.getRate?cid=10000&num=20&start=" & i & "&orderby=profit_ratio&ordertype=desc&qjson="
- With xml
- .Open "GET", Url, False
- .send
- st = Split(Split(.responseText, "johansen062308384298872741413371443299((")(1), "))")(0)
- End With
- Js.AddCode ("dy=" & st)
- n = Js.Eval("dy.data.length")
- For j = 0 To n - 1
- Sid = Js.Eval("dy.data[" & j & "].sid") '取得证券代码
-
- '利用代码进行代码的明细数据查询
- Url = "http://jiaoyi.sina.com.cn/api/jsonp_v2.php/jsonp_1413382356619_19604286/Stockhold_Service.getStockhold?"
- Url = Url + "sid=" & Sid
- Url = Url + "&cid=10000&count=10"
- xml.Open "GET", Url, False
- xml.send
- st = Split(Split(xml.responseText, "jsonp_1413382356619_19604286((")(1), "))")(0)
- Js.AddCode ("dy2=" & st)
- m = Js.Eval("dy2.count")
-
- On Error Resume Next
- For k = 0 To m - 1
- r = r + 1
- arr(r, 1) = Js.Eval("dy.data[" & j & "].rank") '排名
- arr(r, 2) = Js.Eval("dy.data[" & j & "].name") '昵称
- arr(r, 3) = k + 1
- arr(r, 4) = Js.Eval("dy2.data[" & k & "].StockName") & Chr(10) & "(" & Js.Eval("dy2.data[" & k & "].StockCode") & ")"
- arr(r, 5) = Js.Eval("dy2.data[" & k & "].AvailSell")
- arr(r, 6) = Js.Eval("dy2.data[" & k & "].StockAmount")
- arr(r, 7) = Js.Eval("dy2.data[" & k & "].cost")
- '......省略一些取值....方法同上'
- Next k
- Next j
- Next i
- sht1.[a2].Resize(UBound(arr, 1), UBound(arr, 2)) = arr
- End Sub
复制代码
|
|