Getting data from HTML source in VBA (excel)

前端 未结 1 383
眼角桃花
眼角桃花 2021-01-07 12:37

I\'m trying to collect data from a website, which should be manageable once the source is in string form. Looking around I\'ve assembled some possible solutions but have run

1条回答
  •  走了就别回头了
    2021-01-07 13:31

    If I were trying to pull the opening price off from 08/10/12 off of that page, which is similar to what I assume you are doing, I'd do something like this:

        Set ie = New InternetExplorer
        With ie
            .navigate "http://eoddata.com/stockquote/NASDAQ/AAPL.htm"
            .Visible = False
            While .Busy Or .readyState <> READYSTATE_COMPLETE
               DoEvents
            Wend
            Set objHTML = .document
            DoEvents
        End With
        Set elementONE = objHTML.getElementsByTagName("TD")
        For i = 1 To elementONE.Length
            elementTWO = elementONE.Item(i).innerText           
            If elementTWO = "08/10/12" Then
                MsgBox (elementONE.Item(i + 1).innerText)
                Exit For
            End If
        Next i
        DoEvents
        ie.Quit
        DoEvents
        Set ie = Nothing
    

    You can modify this to run through the HTML and pull whatever data you want. Iteration +2 would return the high price, etc.

    Since there are a lot of dates on that page you might also want to make it check that it is between the Recent End of Day Prices and the Company profile.

    0 讨论(0)
提交回复
热议问题