bjay
08-29-2014, 01:50 PM
Hello all;
I tried searching my question on google but couldn't find an answer I'm looking for, probably because I couldn't phrase it properly in a short sentence. So here I am...
I'm trying to access a webpage through Access VBA code, but having trouble getting the "href" form <a> element that don't have a ID or Class.
Here's the example of html I'm trying to access:
<div class="sub_cat_title">
<a href="/somewebsite.com/somepage.htm">Link name</a>
</div>
Here's the VBA I tried:
Dim col As IHTMLElementCollection
Dim elm As IHTMLElement
Set col = html.getElementsByClassName("sub_cat_title")
For Each elm In col
field3 = elm.getAttribute("href")
field2 = elm.outerText
Debug.Print field2 & ", " & field3
Next
As you can expect it only extract the elm.outerText part (Link name) and ignores the elm.getAttribute("heref"). I don't know how to get to the <a> element.
Can someone please help?
Thank you so much for your time.
BJ:)
I tried searching my question on google but couldn't find an answer I'm looking for, probably because I couldn't phrase it properly in a short sentence. So here I am...
I'm trying to access a webpage through Access VBA code, but having trouble getting the "href" form <a> element that don't have a ID or Class.
Here's the example of html I'm trying to access:
<div class="sub_cat_title">
<a href="/somewebsite.com/somepage.htm">Link name</a>
</div>
Here's the VBA I tried:
Dim col As IHTMLElementCollection
Dim elm As IHTMLElement
Set col = html.getElementsByClassName("sub_cat_title")
For Each elm In col
field3 = elm.getAttribute("href")
field2 = elm.outerText
Debug.Print field2 & ", " & field3
Next
As you can expect it only extract the elm.outerText part (Link name) and ignores the elm.getAttribute("heref"). I don't know how to get to the <a> element.
Can someone please help?
Thank you so much for your time.
BJ:)