Search code examples
vbadomshdocvw.internetexplorer

The data in A "id" is not printing


i am trying this

Sub JJ()

Dim IE As New SHDocVw.InternetExplorer
Dim hdoc As MSHTML.HTMLDocument
Dim ha As String

IE.Visible = True
IE.navigate "https://www.nseindia.com/get-quotes/equity?symbol=DIVISLAB"
Do While IE.readyState <> READYSTATE_COMPLETE
Loop

Set hdoc = IE.document
ha = hdoc.getElementById("preOpenFp").innerText
Debug.Print ha
End Sub

Please suggest any solution for that. the point is in image.The point and data i need is marked.


Solution

  • If you want to read the data from the Pre-Open Markt you have to change the url as follows https://www.nseindia.com/get-quotes/equity?symbol=DIVISLAB#info-preopenmkt.Try this code.

    Sub JJ()
    Dim IE
    Set IE = CreateObject("InternetExplorer.Application")
    'Dim IE As New SHDocVw.InternetExplorer
    
    Dim hdoc As MSHTML.HTMLDocument
    Dim ha As String
    IE.Visible = True
    IE.navigate "https://www.nseindia.com/get-quotes/equity?symbol=DIVISLAB#info-preopenmkt"
    
    Do While IE.Busy: DoEvents: Loop
    Do While IE.Busy And Not IE.readyState = READYSTATE_COMPLETE: DoEvents: Loop
    
    'Application.Wait (Now + TimeValue("0:00:15"))
    Set hdoc = IE.document
    
    ha = hdoc.getElementById("preOpenIep").innerText
    
    Debug.Print (ha)
    
    End Sub