一直在本站索予。今天为大家分享一下,如何用EXCEL获得股票API数据?有需要的同学可以拿去,宏代码不够简洁,但不影响使用。现在开始吧!注意:这里并没有任何打广告嫌疑。
第一,本人也是找了很久,终于找到了一个有换手率也有市净率,而且还免费的股票API,先申请吧!百度搜索,shenjian.io
花一分钟申请个免费帐号,然后登录进去点击API接口-股票实时行情查询API-获取API,
然后请求地址:https://api.shenjian.io/?appid=0de306293a36a5930b6b037847e6980e ,就是你个人的免费股票API啦!
第二,EXCEL用宏代码使用调用(为什么选择EXCEL,大家应该懂,容易统计分析,便于查看)。上宏代码
Sub 更新名称()
Dim objXML As Object
Dim txtContent As String
Dim arrT1() As String
Dim arrT2() As String
Dim i, j As Integer
Dim strCode As String
Application.ScreenUpdating = False
Range(Cells(3, 1), Cells(5000, 1)).EntireRow.Delete
Set objXML = CreateObject("Microsoft.XMLHTTP")
With objXML
.Open "GET", "XX填自己申请的请求网址XXXX", False
.send
If objXML.Status = 200 Then
txtContent = .responsetext
arrT1 = Split(txtContent, Chr(34) & "},")
For i = 0 To UBound(arrT1)
arrT2 = Split(arrT1(i), Chr(34) & ",")
For j = 0 To UBound(arrT2)
strCode = Mid(arrT2(j), InStr(arrT2(j), ":" & Chr(34)) + 2)
Cells(i + 3, j + 1) = strCode
Next j
Next i
Else
MsgBox "下载网页数据失败"
End If
Cells(i + 2, j) = Mid(strCode, 1, Len(strCode) - 23)
Set objXML = Nothing
End With
Application.ScreenUpdating = True
Cells(1, 4) = Format(Now(), "yyyy-mm-dd")
End Sub