I am getting a 462 error (the remote server does not exist or is unavailable):
Set QuestionField = html.getElementsByClassName("view-count style-scope yt-view-count-renderer")
I'm pretty sure the view information I'm trying to pull is in a class tag, and I am unsure why getElementsByClassName isn't working to pull this information.
Here is the relevant HTML code from YouTube:
<
span class="view-count style-scope yt-view-count-renderer">952 views
<
/span>
Here is the VBA Code:
Enum READYSTATE
READYSTATE_UNINITIALIZED = 0
READYSTATE_LOADING = 1
READYSTATE_LOADED = 2
READYSTATE_INTERACTIVE = 3
READYSTATE_COMPLETE = 4
End Enum
Sub ImportYTData()
Dim ie As InternetExplorer
Dim html As HTMLDocument
Set ie = New InternetExplorer
ie.Visible = True
ie.navigate "https://www.youtube.com/watch? v=0YNJQNpP9Do&list=PL_Lt8vbVLfk_pzt-TWzfk_GNAKp-ePXc1&index=22"
Do While ie.READYSTATE <> READYSTATE_COMPLETE
Application.StatusBar = "Trying to go to the YouTube Video ..."
DoEvents
Loop
Set html = ie.document
MsgBox html.DocumentElement.innerHTML
Application.StatusBar = ""
Dim RowNumber As Long
Dim QuestionField As IHTMLElement
Dim views As String
Set QuestionField = html.getElementsByClassName("view-count style-scope yt-view-count-renderer")
RowNumber = 4
views = QuestionField.innerText
views = Replace(views, "views", "")
views = Replace(views, "view", "")
Cells(RowNumber, 3).Value = Trim(views)
Set html = Nothing
End Sub