PDA

View Full Version : [SOLVED:] Extracting data in "Treeview" from web using VBA



jiki
04-16-2015, 08:54 PM
Good Day!

I've been trying to extract a Treeview data (5120-24963 in particular) from web with part of its HTML source below using excel VBA. I tried using "getElementsByTagName()" method to no avail. I tried every tags acronym, td, tr, etc., in fact I tried all the tags with the same result.


<td valign="middle">

<a href="javascript:__doPostBack('oTree','oncollapse,0')">
<img class="icon" border="0" align="top" src="/webctrl_client/1_0/treeimages/Rminus.gif"></img>
</a>
<img class="icon" border="0" align="top" src="images/item.gif"></img>
<font size="5" color="#00FFFF" style="display:inline;font-face:Times;text-decoration:none;cursor:h…:hidden;font-size:16;color:#00FFFF;background-color:#08246B;">
<acronym title="LATERAL ACOUSTIC BIRD">

5120 - 24963

</acronym>
</font>

</td>

Please help me for the workaround on this. Thanks

jonh
04-17-2015, 01:25 AM
acronym works in a vbscript. Don't see why it wouldn't in vba...


<html><head><script language='vbscript'>

sub clickme()
set elm = document.getelementsbytagname("acronym")
for each e in elm
s=s & "<p>" & e.innerhtml & "</p>"
next
result.innerhtml = s
end sub

</script></head><body><table><tr>
<td valign="middle">
<font size="5" color="#00FFFF" style="display:inline;font-face:Times;text-decoration:none;cursor:h…:hidden;font-size:16;color:#00FFFF;background-color:#08246B;">
<acronym title="LATERAL ACOUSTIC BIRD">5120 - 24963</acronym></font></td></tr></table>
<button onclick='clickme'>clicky</button><div id='result'></div>
</body></html>

jiki
04-17-2015, 09:57 PM
I tried the code but still I got empty. But when I replaced and tried using the tag "td" instead of "acronym' and with some string manipulation, at last I got the data I wanted. The problem is before I always used the attribute "innertext" instead of "innerhtml". But still I don't know why I got nothing when I used the tag "acronym". Still, I'm happy that this is resolved, big thanks jonh.