Retuning a value from <a href=…

ScooterNorm

New Member
Joined
Feb 25, 2024
Messages
22
Office Version
  1. 2016
Platform
  1. Windows
I’m trying to get the value from there <a href… elements. Here's where I'm stuck.
I've done the following but then I can't figure out what to do next: ht.getElementsByClassName("value").getElementsByTagName("a").innerHTML
Thanks for your help,
Here's the HTML which I think is relevant.
...
<div class="double table">
<div class="row">
<div class="key">Correspondent Addr:</div>
<div class="value">
<a href="MyAddr@gmailcom">MyAddr@gmailcom</a>
<a href="My22@gmail.com">My22@gmail.com</a>
</div>
<div class="key">Correspondent Addr Authorized:</div>
<div class="value"> Yes </div>
</div>
</div>
...

Note: I’m a novice at this and any help would be appreciated.
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
For your first email address...

VBA Code:
ht.getElementsByClassName("value")(0).getElementsByTagName("a")(0).innerText

For your second email address...

VBA Code:
ht.getElementsByClassName("value")(0).getElementsByTagName("a")(1).innerText

Note the following...

VBA Code:
ht.getElementsByClassName("value") refers to the collection of elements with "value" as their class name.

ht.getElementsByClassName("value")(0) refers to the first element in the collection of elements with "value" as their class name.

ht.getElementsByClassName("value")(0).getElementsByTagName("a") refers to the collection of elements with "a" as their tag name within the first element that contains "value" as its class name.

ht.getElementsByClassName("value")(0).getElementsByTagName("a")(0) refers to the first element in the collection of elements with "a" as their tag names withn the first element that contains "value" as its class name.

Hope this helps!
 
Last edited:
Upvote 1
Solution
For your first email address...

VBA Code:
ht.getElementsByClassName("value")(0).getElementsByTagName("a")(0).innerText

For your second email address...

VBA Code:
ht.getElementsByClassName("value")(0).getElementsByTagName("a")(1).innerText

Note the following...

VBA Code:
ht.getElementsByClassName("value") refers to the collection of elements with "value" as their class name.

ht.getElementsByClassName("value")(0) refers to the first element in the collection of elements with "value" as their class name.

ht.getElementsByClassName("value")(0).getElementsByTagName("a") refers to the collection of elements with "a" as their tag name within the first element that contains "value" as its class name.

ht.getElementsByClassName("value")(0).getElementsByTagName("a")(0) refers to the first element in the collection of elements with "a" as their tag names withn the first element that contains "value" as its class name.

Hope this helps!
Hey Dominic,
Thanks for sharing these suggestions. With this starting point and a lot of head pounding against the wall, I got it to work.
Only one strange anomaly. About 25% or so of the time the IE page does not load.
Another person suggested looking into using ServerXMLHTTP60 instead of IE since I don't need the web page loaded.
So I'll be looking into that and if you have any pointers about using ServerXMLHTTP60, I'm all ears.
Thanks again and I'll mark this solved by you,
-Norm
 
Upvote 0
Another person suggested looking into using ServerXMLHTTP60 instead of IE since I don't need the web page loaded.

Actually, that's the method I too would suggest you use, and it's the alternative method I post in your previous thread, which you'll find here .
 
Upvote 1
Actually, that's the method I too would suggest you use, and it's the alternative method I post in your previous thread, which you'll find here .
OK, great, I'm a bit overloaded with new stuff and I missed it.
Thanks again,
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,265
Members
452,627
Latest member
KitkatToby

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top