Count child on a website

Hi,

I’m creating a code that goes to a website and collects information. I need to know how many times a tag occurs. I’ve tried a lot of counting tricks but nothing seems to work. The structure of the website is similar to the following.
I need to know how many times the tag ‘<Li’ occurred in the path Main > Second > third.

Any idea on how to do that ?

Thanks a lot for your help guys !

<Main 
  <Second
    <Third
      <Li Information 1 </Li>
      <Li Information 2 </Li>
      <Li Information 3</Li>
    </Third>
  </Second>    
</Main>

Hello @Spooks76, welcome to the GitHub Support Community!

Are you using JavaScript or another programming language to count these tags?

With JavaScript, you could use document.querySelectorAll() to return a collection of nodes that match the given selectors, then use the length property to return the total number of nodes.

document.querySelectorAll('main > second > third > li').length;

If you’re not using JS, it would be great if you could clarify what programming language you’re using.

1 Like