|
楼主 |
发表于 2014-10-14 10:16
|
显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
本帖最后由 onlycxb 于 2014-10-14 18:59 编辑
分享4:论坛问题http://club.excelhome.net/thread-1158114-1-1.html
抓取东方财富网数据
- 'Option Explicit
- '************************************************************
- '作 者: DongYu QQ:470208739 2014/10/14
- '************************************************************
- Sub 沪深A股()
- '需求:抓取http://data.eastmoney.com/cmjzd/,抓取沪深A股
- Dim xml As New MSXML2.XMLHTTP, strTxt As String, Url As String, js, Slen As Integer
- Dim i As Integer, arr, j
- Cells.ClearContents
- Url = "http://datainterface.eastmoney.com/EM_DataCenter/JS.aspx?type=GG&sty=GDRS&st=2&sr=true&p=1&ps=50&js=var%20ZWsofIjH={pages:(pc),data:[(x)]}&mkt=1&fd=2014-9-30&rt=47108232"
- With xml
- .Open "GET", Url, False
- .send
- strTxt = Split(.responseText, "var ZWsofIjH=")(1)
- End With
- Set js = CreateObject("scriptcontrol")
- js.Language = "jscript"
- js.AddCode ("dy= " & strTxt)
- Slen = js.eval("dy.data.length") - 1
- ReDim arr(1 To Slen + 1, 1 To 14)
- For i = 0 To Slen
- For j = 1 To 12
- arr(i + 1, j) = Split(js.eval("dy.data[" & i & "]"), ",")(j - 1)
- Next j
- Next i
- With Sheet1
- .[b2].Resize(UBound(arr, 1), UBound(arr, 2)) = arr
- For i = 2 To UBound(arr, 1) + 1
- .Cells(i, 1) = i - 1
- .Cells(i, 2).NumberFormatLocal = "000000"
- If Abs(.Cells(i, 5)) > 1 Then .Cells(i, 5) = "-" Else .Cells(i, 5).NumberFormatLocal = "0.00%"
- .Cells(i, 6) = Round(.Cells(i, 6))
- '其他省略..
- Next i
- End With
- End Sub
复制代码 为方便阅读代码,附数据结构图
|
|