manofcheese
New Member
- Joined
- Jan 5, 2019
- Messages
- 8
I am trying to find a good way to convert an HTML document to XML so I can use an Xpath expression for parsing. As a test I'd like to get this xpath expression to pull information from What Is My IP Shows your real public IP address - IPv4 - IPv6
So far this is what I have but I haven't been able to get the response converted to XML yet.
XML:
//*[@id="post-7"]/div[1]/div[1]/div/ul/li[2]
So far this is what I have but I haven't been able to get the response converted to XML yet.
VBA Code:
Sub xpathTest()
Dim myURL As String
Dim strPath As String
Dim xml_obj As Object
myURL = "https://www.whatismyip.com/"
Set xml_obj = CreateObject("MSXML2.XMLHTTP")
xml_obj.Open "GET", myURL, False
xml_obj.Send
Set myxml = xml_obj.responseXML
strPath = "//*[@id=" & """" & "post-7" & """" & "]/div[1]/div[1]/div/ul/li[2]"
Dim dom As DOMDocument30
Dim nodelist As IXMLDOMNodeList
myxml.SetProperty "SelectionLanguage", "XPath"
Set nodelist = myxml.DocumentElement.SelectNodes(strPath)
Debug.Print "Found " & nodelist.Length & " Node"
Debug.Print result
End Sub