I have created a macro that finds people from the website online base (using their pin numbers) and I want to copy some information about them to excel (like their name, status etc.). The search reasult is a table that contains text and objects (svg) and I have the problem with copying objects to excel. The search result looks like that:
<td data-label="Full name">Name</td>
<td data-label="Status" class="results-status">
<svg role="presentation"><use xlink:href="/static/img/sprite.svg#status-caution"></use></svg>
</td>
<td data-label="Location">UK</td>
<td data-label="Details"></td>
So I wrote this:
Set elements = doc.getElementsByTagName("td")
Cells(i, 1).Value = elements(0).innerText
Cells(i, 3).Value = elements(1).innerText
Cells(i, 4).Value = elements(2).innerText
Cells(i, 5).Value = elements(3).innerText
And unfortunately I don't get anything from elements(1). I guess it doesn't work because this is an object not a text.
I have to get status information from the 2nd row (/static/img/sprite.svg#status-caution) and I don't have any idea how to do this. I also triedimg = elements(1).getAttribute()
but msgbox(img) showed only this: [native code]
Please try this:
Explain:
Because elements are set as
doc.getElementsByTagName("td")
and the tagname "use" is under two level, addChildren(0).Children(0).
orfirstElementChild.firstElementChild
to gethref
.elements(1).Children(0).Children(0).href
gets nothing, instead, take.getAttribute("xlink:href")
to replace.href
.Or another solution would be:
Attached screenshot of working code and tested