'Unable to GET a value associated to div Tag <div class="name"> Value </div>
I'm using VBA to pull a value from a nested Div Tags, as shown on below image:
HTML code:
<div class="styles__SCFileModuleFooter-e6rbca-1 kUUNkj">
Constituída em 26-02-1962
</div>
I'm using the code Below to access class="styles__SCFileModuleFooter-e6rbca-1 kUUNkj", and pull the value "Constituída em 26-02-1962", but seems it is not capable to find that class in the loop:
Dim XMLPage As New MSXML2.XMLHTTP60
Dim HTMLDoc As New MSHTML.HTMLDocument
Dim htmlEle1 As MSHTML.IHTMLElement
Dim htmlEle2 As MSHTML.IHTMLElement
Dim URL As String
Dim elemValue As String
URL = "https://www.informadb.pt/pt/pesquisa/?search=500004064"
XMLPage.Open "GET", URL, False
XMLPage.send
HTMLDoc.body.innerHTML = XMLPage.responseText
For Each htmlEle1 In HTMLDoc.getElementsByTagName("div")
Debug.Print htmlEle1.className
If htmlEle1.className = "styles__SCFileModuleFooter-e6rbca-1 kUUNkj" Then
elemValue = Trim(htmlEle1.innerText)
If InStr(UCase$(elemValue), "CONSTITU") > 0 Then
'Found Value
Exit For
End If
End If
Next htmlEle1
There are some cases where the class="styles__SCFileModuleFooter-e6rbca-1 kUUNk" appears more than once, that's the reason for the checking If InStr(UCase$(elemValue), "CONSTITU") > 0 Then.
Can anyone help please?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|

