|
VBA万岁 发表于 2014-10-14 12:07
第7句代码“xml As New MSXML2.XMLHTTP”出错,弹出的错误提示为“User-defined-type not defined”——是 ...
我这里改为如下代码时运行正常:
'Option Explicit
'************************************************************
'作 者: DongYu QQ:470208739 2014/10/14
'************************************************************
Sub 沪深A股()
'需求:抓取http://data.eastmoney.com/cmjzd/,抓取沪深A股
Dim 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 CreateObject("msxml2.xmlhttp")
.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
|
|