|
需求描述:我想抓取东方财富网上的个股资金流的相关数据,我首先尝试了用PQ进行网抓,返回的数据清洗过之后,是标准的json格式的数据,直接很快就能解析出来,抓出来的效果如表格所示。
我有试着尝试 用VBA的方法进行抓取,能抓取到数据,但是JSON的格式数据解析一直有问题,一直解析不出来,试了两种方法,都没有成功 哪位老师给帮忙看下,谢谢。
看书上找了一个相似的代码,模仿着修改了下,但是一直没有成功,相关参考代码如下: 附件也已经上传
- Sub WebCatchJSONData2() '修改尝试
- Dim objXMLHTTP As Object
- Dim objDOM As Object
- Dim objWindow As Object
- Dim strURL As String
- Dim strText As String
- Dim intPageNum As Integer
- Dim i As Integer
- Dim j As Integer
- Dim lngRow As Long
- Dim intCol As Integer
- Dim avntTitle As Variant
- Set objXMLHTTP = CreateObject("MSXML2.XMLHTTP")
- Set objDOM = CreateObject("htmlfile")
- Set objWindow = objDOM.parentWindow
- Application.ScreenUpdating = False
- 'strURL = "http://stockdata.stock.hexun.com/" _
- & "rzrq/data/Stock/DetailCollectDay.ashx"
- strURL = "https://push2.eastmoney.com/api/qt/clist/get?cb=jQuery112304205458899914081_1717003845816&fid=f62&po=1&pz=50&pn=3&np=1&fltt=2&invt=2&ut=b2884a393a59ad64002292a3e90d46a5&fs=m%3A0%2Bt%3A6%2Bf%3A!2%2Cm%3A0%2Bt%3A13%2Bf%3A!2%2Cm%3A0%2Bt%3A80%2Bf%3A!2%2Cm%3A1%2Bt%3A2%2Bf%3A!2%2Cm%3A1%2Bt%3A23%2Bf%3A!2%2Cm%3A0%2Bt%3A7%2Bf%3A!2%2Cm%3A1%2Bt%3A3%2Bf%3A!2&fields=f12%2Cf14%2Cf2%2Cf3%2Cf62%2Cf184%2Cf66%2Cf69%2Cf72%2Cf75%2Cf78%2Cf81%2Cf84%2Cf87%2Cf204%2Cf205%2Cf124%2Cf1%2Cf13"
-
- avntTitle = Array("f1", "f2", "f3", "f12", "f13", "f14", "f62", "f66", "f69", "f72", "f75", "f78", "f81", "f84", "f87", "f124", "f184", "f204", "f205", "f206")
- ActiveSheet.UsedRange.Offset(1).ClearContents
- lngRow = 1
- ' Do While True
- ' intPageNum = intPageNum + 1
- With objXMLHTTP
- .Open "GET", strURL, False
- .send
- strText = .responseText
- End With
- strText = Split(Split(strText, "]")(0), "[")(1)
- 'If Len(strText) = 0 Then Exit Do
- strText = "<script>data=[" & strText & "]</script>"
- objDOM.Write strText
- For i = 0 To objWindow.eval("data.length") - 1
- lngRow = lngRow + 1
- intCol = 0
- For j = 0 To UBound(avntTitle)
- intCol = intCol + 1
- Cells(lngRow, intCol) = objWindow.eval("data[" & i & "]." & avntTitle(j))
- Next j
- Next i
- ' Loop
- Application.ScreenUpdating = True
- Set objXMLHTTP = Nothing
- Set objDOM = Nothing
- Set objWindow = Nothing
- End Sub
复制代码
|
|