I have been looking for the answer on this question for quite some time. Below here i have two parts of code that load html of a website into memory. Same result. But de getelements methods, for example getelementsbyclassname do not work when i use the 'Get' method. I wanted to use the quicker 'Get' method but due to this different outcome I couldn't. In the first line of code getElementsByClassName works, but in the second part its outcome remains nothing.
I really couldn't figure out why, I have been stuck for some time now. I hope here you can help met out. Thank you in advance.
<i>Dim IE As New SHDocVw.InternetExplorer
Dim HTMLDoc As New MSHTML.HTMLDocument
Dim URL As String
Dim Element1 As MSHTML.IHTMLElement, Element2 As MSHTML.IHTMLElement,
Element3 As MSHTML.IHTMLElement
Dim Elementen As MSHTML.IHTMLElementCollection
URL = "https://www.google.nl/?gfe_rd=cr&dcr=0&ei=KXNcWsHNJ9OB4gTcjqvwCA"
IE.Visible = True
IE.navigate URL
Do While IE.readyState <> READYSTATE_COMPLETE
DoEvents
Loop
Set HTMLDoc = IE.document
Set Element1 = HTMLDoc.getElementsByClassName("gsfi")(0)
Set Element2 = HTMLDoc.getElementById("lst-ib")
Debug.Print Element1.className, Element2.className
Dim XMLPage As New MSXML2.XMLHTTP60
Dim HTMLDoc As New MSHTML.HTMLDocument
Dim URL As String
Dim Element1 As MSHTML.IHTMLElement
Dim Element2 As MSHTML.IHTMLElement
URL = "https://www.google.nl/?gfe_rd=cr&dcr=0&ei=KXNcWsHNJ9OB4gTcjqvwCA"
XMLPage.Open "Get", URL, False
XMLPage.send
HTMLDoc.body.innerHTML = XMLPage.responseText
Set Element1 = HTMLDoc.getElementsByClassName("gsfi")(0)
Set Element2 = HTMLDoc.getElementById("lst-ib")
Debug.Print Element2.className</i>