I’m trying to retrieve a list of attendees to an event on a webpage. If I use a browser, to the webpage, right click, and choose View Page Source I can see the names of the attendees.
I need to do this with VBA. I have tried 3 different properties (objIE.Document.body.innerText, objIE.Document.body.innerHTML, objIE.Document.body.textContent) of the IE object and none return the attendee names. Something is going on behind the scenes. How do I fix this?
Public Sub OpenWebsiteAndRetrieveData()
Dim objIE As Object
Dim strURL As String
Dim strPageContent As String
Dim strinnerText As String
Dim strinnerHTML As String
Dim strTextContent As String
' Initialize the URL
strURL = "https://meetup.com/cflfreethought/events/301401141/attendees/"
' Create an Internet Explorer instance
Set objIE = CreateObject("InternetExplorer.Application")
' Navigate to the URL
objIE.Navigate strURL
' Wait for the page to fully load
Do While objIE.Busy Or objIE.ReadyState <> 4
DoEvents
Loop
' Make the Internet Explorer visible (optional)
objIE.Visible = True
' Retrieve the inner text of the webpage
strinnerText = objIE.Document.body.innerText
strinnerHTML = objIE.Document.body.innerHTML
strTextContent = objIE.Document.body.textContent
' Output the content (for demonstration purposes)
Debug.Print "innerText:", Len(strinnerText), InStr(strinnerText, "David")
Debug.Print "innerHTML:", Len(strinnerHTML), InStr(strinnerHTML, "David")
Debug.Print "TextContent:", Len(strTextContent), InStr(strTextContent, "David")
' Clean up
objIE.Quit
Set objIE = Nothing
Stop
MsgBox "Done"
End Sub
Brooks is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.