|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
onlycxb 发表于 2014-11-10 20:21
此例可不用抓包,但速度不及楼上的快,代码如下:
Sub 董监高及相关人员持股变动明细2()
Dim xml As New MSXML2.XMLHTTP, url As String, St, St2 As String
Dim js, dy, ps, pc, pt As Integer, p As Integer, a
Application.ScreenUpdating = False
Cells.ClearContents
'Range("a1:o1") = Array("日期", "代码", "名称", "相关", "变动人", "变动股数", "成交均价", "变动金额(万)", "变动原因", "变动比例(%)", "变动后持股数", "持股种类", "董监高人员姓名", "职务", "变动人与董监高的关系")
Range("a1:o1") = Array("变动比例(%)", "董监高人员姓名", "代码", "变动人", "持股种类", "日期", "变动股数", "变动后持股数", "成交均价", "名称", "变动人与董监高的关系", "变动原因", "变动金额(万)", "职务", "相关")
url = "http://data.eastmoney.com/executive/list.html"
With xml
.Open "GET", url, False
.send
'Debug.Print .responseText
St = Split(Split(.responseText, "defjson:")(1), "," & vbNewLine & " maketr:")(0)
Set js = CreateObject("scriptcontrol")
js.Language = "javascript"
js.addcode ("首页数据= " & St)
ps = js.Eval("首页数据.data.length")
pc = UBound(Split(js.Eval("首页数据.data[0]"), ","))
pt = js.Eval("首页数据.pages")
MsgBox "总页数:" & pt & ",每页有" & ps & "条记录,每条记录有" & pc + 1 & "项"
For p = 1 To 2 '2改为Pt可获得所有页码的数据
.Open "GET", "http://datainterface.eastmoney.com/EM_DataCenter/JS.aspx?type=GG&sty=GGMX&p=" & p & "&ps=" & ps & "&js=var {jsname}={pages:(pc),data:[(x)]}{param}", False
.send
'Debug.Print .responseText
St2 = Split(Split(.responseText, "var {jsname}=")(1), "{param}")(0)
js.addcode ("分页数据= " & St2)
Set dy = js.Eval("分页数据.data")
ReDim arr(1 To ps, 1 To pc + 1)
i = 0
For Each a In dy
i = i + 1
For j = 1 To pc + 1
Cells((p - 1) * 50 + 1 + i, 1).Resize(, pc + 3) = Split(a, ",")
Next j
Next a
Next p
End With
Range("L2:L" & ActiveSheet.UsedRange.Rows.Count).Delete Shift:=xlToLeft
Application.ScreenUpdating = True
End Sub
|
|