以下是我用来获取下面提到的特定变量的代码。
Option Explicit
Public Sub GetInfo()
Dim s As String, ids(), i As Long
ids = Array(500325, 500510)
With CreateObject("MSXML2.XMLHTTP")
For i = LBound(ids) To UBound(ids)
.Open "GET", "https://api.bseindia.com/BseIndiaAPI/api/ComHeader/w?quotetype=EQ&scripcode=" & ids(i) & "&seriesid=", False
.send
s = .responseText
ActiveSheet.Cells(i + 1, 1) = Split(Split(s, """ROE"":""")(1), Chr$(34))(0)
ActiveSheet.Cells(i + 1, 2) = Split(Split(s, """PE"":""")(1), Chr$(34))(0)
ActiveSheet.Cells(i + 1, 3) = Split(Split(s, """PB"":""")(1), Chr$(34))(0)
Next
End With
End Sub
但是我无法做进一步的事情,特别是在“结果和股权模式”框中提到的内容,因为我之前认为代码将与该门户网站上提到的所有变量一起使用。是否与api或其他有关?由于我对api不太了解,因此建议在这方面。
链接以供您参考: https://www.bseindia.com/stock-share-price/larsen--toubro-ltd/lt/500510/
https://www.bseindia.com/stock-share-price/reliance-industries-ltd/reliance/500325/
答案 0 :(得分:0)
您的数组错误。声明动态数组,然后分配给它。
Option Explicit
Public Sub GetInfo()
Dim s As String, ids(), i As Long
ids = Array(500325, 500510)
With CreateObject("MSXML2.XMLHTTP")
For i = LBound(ids) To UBound(ids)
.Open "GET", "https://api.bseindia.com/BseIndiaAPI/api/ComHeader/w?quotetype=EQ&scripcode=" & ids(i) & "&seriesid=", False
.send
s = .responseText
ActiveSheet.Cells(i + 1, 1) = Split(Split(s, """ROE"":""")(1), Chr$(34))(0)
ActiveSheet.Cells(i + 1, 2) = Split(Split(s, """PE"":""")(1), Chr$(34))(0)
ActiveSheet.Cells(i + 1, 3) = Split(Split(s, """PB"":""")(1), Chr$(34))(0)
Next
End With
End Sub