I am trying to write code that will sift through this DOM structure:
<html>
<head>
<body>
<table id="the-table" border="1">
<thead>
<tbody>
<tr> </tr>
<tr>
<td class="x-grid3-hd-inner" bgcolor="#8dd5e7" colspan="7">
</tr>
<tr>
<td class="x-grid3-hd-inner" bgcolor="#8dd5e7" colspan="7">
</tr>
<tr>
<tr>
<td class="oneline">2</td>
<td class="oneline">ENB</td>
<td class="oneline">2</td>
<td class="oneline">CELL_99</td>
<td class="oneline">255.255.255.0</td>
<td class="oneline">My Group</td>
<td class="oneline">*</td>
</tr>
<tr>
<tr>
<tr>
...
<tr>
<tr>
</tbody>
</table>
</body>
</html>
I am trying to extract the text at each td element for all tr elements of the table. I expanded one example out above. All td elements of the table are formatted using the same html structure (besides the title of the table). This is the method that I have used so far.
Sub ParseWebPage(url As String, sheet As String, searchCrit As String)
Dim objXML As MSXML2.DOMDocument
Set objXML = New MSXML2.DOMDocument
Set htm = CreateObject("htmlFile")
With CreateObject("msxml2.xmlhttp")
.Open "GET", url, False
.send
xmlresp = .responseText
End With
objXML.loadXML (xmlresp)
Dim objElem As MSXML2.IXMLDOMElement
Debug.Print xmlresp
objXML.loadXML (xmlresp)
Set objElem = objXML.selectSingleNode("tr")
Debug.Print "Found" & objElem.text
End Sub
The problem is, every time my objElem returns back empty. I also tried using a NodeList instead of IXMLDOMElement but it always returned empty.
I believe the issue to be the string argument. I have tried using "tr", "oneline", "/html/body/table/tbody", and creating a loop for each "/html/body/table/tbody/tr[x]/td[y]" but none of these were effective.
Can someone help me out here?