Hi everyone,
I am trying to read HTML documents using XPath in VBA. AS an easy example: Get my IP address fom whatismyip.com.
The problem: The only Xpath query that returns anything is "/". Everything else just does not return anything and the NodeList remains empty.
Does anyone have an idea where I'm going wrong?
I am trying to read HTML documents using XPath in VBA. AS an easy example: Get my IP address fom whatismyip.com.
The problem: The only Xpath query that returns anything is "/". Everything else just does not return anything and the NodeList remains empty.
Does anyone have an idea where I'm going wrong?
Code:
Sub GetData()
Dim objhttp As Object
Dim XMLDatei As String
Dim ResultList As IXMLDOMNodeList
Dim i As Integer
Dim counter As Integer
Dim xml As New DOMDocument
Dim XPathQuery As String
Dim URL As String
XPathQuery = "//div[@id='ip']"
URL = "http://www.whatismyip.com"
Set objhttp = CreateObject("MSXML2.ServerXMLHTTP.6.0")
objhttp.Open "GET", URL, False
objhttp.send ("")
xml.Load xmlsource:=objhttp.responseText
xml.setProperty Name:="SelectionLanguage", Value:="XPath"
Set ResultList = xml.SelectNodes(XPathQuery)
counter = ResultList.Length
For i = 0 To counter
Debug.Print ResultList.Item(i).nodeName
Next i
End Sub