Looking for some help. I'm using this code right now to scrape the innertext of all <li>s on a webpage where the class name is "error' (e.g. <li class="error">, within a DIV tag.
However it doesn't work when there is no DIV tag on a page. Can anyone help me to do the same thing, but without there being a DIV on the page and so that if there is a tag with <li class="error">XYZ"</li>, it will extract XYZ as the innertext.
Set Divelements = htm.getElementsByTagName("li")
For Each divElement In Divelements
If InStr(1, divElement.className, "error") Then
Debug.Print divElement.InnerText
t1 = t
For Each El In divElement.ParentNode.getElementsByTagName("p")
o.Cells(t1, 2) = El.InnerText
t1 = t1 + 1
Next El
t = t1
Exit For 'only the first loop
End If
Next
i = i + 1
However it doesn't work when there is no DIV tag on a page. Can anyone help me to do the same thing, but without there being a DIV on the page and so that if there is a tag with <li class="error">XYZ"</li>, it will extract XYZ as the innertext.
Set Divelements = htm.getElementsByTagName("li")
For Each divElement In Divelements
If InStr(1, divElement.className, "error") Then
Debug.Print divElement.InnerText
t1 = t
For Each El In divElement.ParentNode.getElementsByTagName("p")
o.Cells(t1, 2) = El.InnerText
t1 = t1 + 1
Next El
t = t1
Exit For 'only the first loop
End If
Next
i = i + 1