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

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.

Forum statistics

Threads
1,215,364
Messages
6,124,507
Members
449,166
Latest member
hokjock

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