|
楼主 |
发表于 2017-11-2 09:24
|
显示全部楼层
三还是split
用split解析有时比较麻烦,需要一步步接近所需数据,虽然麻烦,但是能得到数据。特别是在获取财经类数据是,虽然能用 Set js =CreateObject("MSScriptControl.ScriptControl") js.Language = "javascript"能获取数据,但是在64位的机子上就趴窝,就运行不了,如果没有找到很好的办法,那就用用split吧。下面举例说明。
列一
全部数据的地址:
http://data.eastmoney.com/DataCe ... DateTime=2017-11-01
一条数据的地址:
http://data.eastmoney.com/DataCe ... DateTime=2017-11-01
不做处理返回的数据:
数据的机构: var IBFdtAvr={"success":true,"pages":1995,"data":[{}.......{}],"url":"http://datainterface3.eastmoney.com//EM_DataCenter_V3/api/CJRL/GetCJRL?tkn=eastmoney&type=1&startDate=2017-01-01&endDate=2017-11-01&pageNum=1&pageSize=1&sortdirect=0&cfg=cjhyrl"}
所需的数据在红色部分{}.......{},别的都是绿叶衬托说明用的. 那就用大体切割一下 Split(Split(tt, "[{")(1), "}]")(0).返回的数据如下:
切割前后的对比,tt1快要接近所要的数据啦,贴一个切割后的数据:{},{},........{},仔细观察每条数据都在{}中,每条数据是以},{间隔,继续split。语句 Split(tt1, "},{"),返回的结果如下
每条数据都显现出来了,下面进行精细切割
以ghb(17)为例 .获得具体的数据。如果想获得全部的数据,遍历一下数据即可。
Split(Split(ghb(17), """:""")(1), """")(0) & "__ " & Split(Split(ghb(17), """:""")(2), """")(0) _
& vbCrLf & Split(Split(ghb(17), """:""")(5), """")(0) & "__ " & Split(Split(ghb(17), """:""")(6), """")(0) _
& vbCrLf & Split(Split(ghb(17), """:""")(7), """")(0) & "__" & Split(Split(ghb(17), """:""")(8), """")(0) _
& vbCrLf & Split(Split(ghb(17), """:""")(9), """")(0) & "__" & Split(Split(ghb(17), """:""")(10), """")(0) _
& vbCrLf & Split(Split(ghb(17), """:""")(11), """")(0) & "__" & Split(Split(ghb(17), """:""")(12), """")(0) _
& vbCrLf & Split(Split(ghb(17), """:""")(13), """")(0) & "__" & Split(Split(ghb(17), """:""")(14), """")(0) _
& vbCrLf & Split(Split(ghb(17), """:""")(15), """")(0) & "__" & Split(Split(ghb(17), """:""")(16), """")(0) _
& vbCrLf & Split(Split(ghb(17), """:""")(17), """")(0) 废话不多说。上截图验证一下.
最后附上代码:
- Sub KaoHsing()
- t = Timer
- Dim sURL$, Pages%
- Dim tt$, tt1$
- Dim ghb, kao
- Dim i%, j%, k%
- ka = Array(, 0, 16, 1, 13, 14, 15, 2, 8, 9)
- URL = "http://data.eastmoney.com/DataCenter_V3/cjrl/getData.ashx?&pagesize=50&page=1&js=var%20IBFdtAvr¶m=&" _
- & "sortRule=1&sortType=ConferenceDate&code=&startDateTime=" & InputBox("请输入开始年月日(yyyy-mm-dd)", "温馨提示", "2017-01-01") & "&endDateTime=" & InputBox("请输入结束年月日", "温馨提示", "2017-11-01")
- Application.ScreenUpdating = False
- ActiveSheet.UsedRange.Offset(1, 0).Clear
- With CreateObject("WinHttp.WinHttpRequest.5.1")
- .Open "GET", URL, False
- .send
- Pages = Split(Split(.responsetext, "pages"":")(1), ",""data")(0) * 50
- .Open "GET", Replace(URL, "50", Pages), False
- .send
- tt = .responsetext
- tt1 = Split(Split(tt, "[{")(1), "}]")(0)
- ghb = Split(tt1, "},{")
- Stop
- End With
- 'Debug.Print ghb(17)
- Debug.Print "------------------------- " & _
- vbCrLf & Split(Split(ghb(17), """:""")(1), """")(0) & "__ " & Split(Split(ghb(17), """:""")(2), """")(0) _
- & vbCrLf & Split(Split(ghb(17), """:""")(5), """")(0) & "__ " & Split(Split(ghb(17), """:""")(6), """")(0) _
- & vbCrLf & Split(Split(ghb(17), """:""")(7), """")(0) & "__" & Split(Split(ghb(17), """:""")(8), """")(0) _
- & vbCrLf & Split(Split(ghb(17), """:""")(9), """")(0) & "__" & Split(Split(ghb(17), """:""")(10), """")(0) _
- & vbCrLf & Split(Split(ghb(17), """:""")(11), """")(0) & "__" & Split(Split(ghb(17), """:""")(12), """")(0) _
- & vbCrLf & Split(Split(ghb(17), """:""")(13), """")(0) & "__" & Split(Split(ghb(17), """:""")(14), """")(0) _
- & vbCrLf & Split(Split(ghb(17), """:""")(15), """")(0) & "__" & Split(Split(ghb(17), """:""")(16), """")(0) _
- & vbCrLf & Split(Split(ghb(17), """:""")(17), """")(0) & "__" & Split(ghb(17), """:""")(18)
- For i = 0 To UBound(ghb)
- If InStr(ghb(i), "ContentFlag"":""1") Then
- kao = Split(ghb(i), """,""")
- k = k + 1
- Cells(k + 1, 1) = k
- For j = 1 To UBound(ka)
- Cells(k + 1, j + 1) = Split(kao(ka(j)), ":""")(1)
- Next
- End If
- Next
- Columns("B:C").NumberFormatLocal = "yyyy/m/d"
- Application.ScreenUpdating = True
- MsgBox "用时" & Timer - t & vbCrLf & "找到" & k & "条信息."
- End Sub
复制代码
|
评分
-
1
查看全部评分
-
|