Loop Through Elements of Website

Joby05

New Member
Joined
Jun 27, 2016
Messages
1
Hi everyone,

I'm trying to get VBA to scrape info from a website and I have gotten most of the way through but I am struggling to loop through several layers of nesting.

The HTML code looks roughly like this:

div class: "group 1"
div class: "group main"
span class: "group main title"
table class: "group table"
td class: "group properties"
div class: "group 2"
with multiple groups in the main and sub div classes.

I'm having a hard time referencing all of the pieces. I am able to use IE.document.getElementsByClassName("group") to cycle through the main groups but after that the sub classes are getting me messed up. I want to be able to loop through subclasses of subclasses potentially so I need help understanding the syntax. I know there is some sort of way to loop through using something like IE.document.getElementsByClassName("group")(0).getElementsByClassName("group_1_main") but I need to write if statements and pull out only specific pieces as listed above without grabbing the many elements between. I think most of my struggle is that the iHTMLElement object doesn't seem to have a good way for me to loop through (something like for i = 0 to max_count) or something. Hopefully what I'm asking isn't too confusing.

<tbody>
</tbody>
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest

Forum statistics

Threads
1,214,614
Messages
6,120,533
Members
448,969
Latest member
mirek8991

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