I wan to pull Buy and sell quantities data from NSE website using XMLHTTP only as it can pull data very fast (The regular method of Set ie = CreateObject("InternetExplorer.Application")
) takes very long time to pull datas for 100+ stocks.
Initially I tried with "MSXML2.XMLHTTP" method, I was not able to pull the data as the response text received is none. Later on after reading several trouble shooting, I found some solution from this site itself that first write the HTML document to text file then try to extract.
After using that method, some improvements made that, the response text received with all HTML elements except my required field. I was able to see my required getdocumentbyid yet I am not able to gets its inner text. The inner text received as "-"
.
Can any one please help?
Attaching my code here
Public Sub GetInfo()
Dim sResponse As String, I As Long, html As New HTMLDocument, hTable As HTMLTable
With CreateObject("MSXML2.XMLHTTP")
.Open "GET", "https://www.nseindia.com/get-quotes/equity?symbol=VOLTAS", False
.send
Application.Wait Now + TimeValue("00:00:01")
sResponse = StrConv(.responseBody, vbUnicode)
End With
sResponse = Mid$(sResponse, InStr(1, sResponse, "<!DOCTYPE "))
WriteTxtFile sResponse
With html
.body.innerHTML = sResponse
Set hTable = .getElementById("orderBuyTq")
Debug.Print hTable.innerHTML 'It gives output as "-"
End With
End Sub
Public Sub WriteTxtFile(ByVal aString As String, Optional ByVal filePath As String = "E:\Share Market\Test.txt")
Dim fso As Object, Fileout As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Set Fileout = fso.CreateTextFile(filePath, True, True)
Fileout.Write aString
Fileout.Close
End Sub