🚀 We are hiring! See open positions

How to count selections in XPath and why?

by Bernardas Alisauskas May 29, 2023 1 min read

Counting selection can be a very powerful feature in XPath when parsing web scraped HTML pages. Selection count can be used to navigate complex trees where parsing by attributes or values is not possible.

For this count() function can be used. See these interactive examples:

<!-- select only paragraphs related to product data but not metadata --> <article> <h2>Data</h2> <!-- this section contains product information --> <p>price: 199</p> <p>year: 2023</p> <h2>Data</h2> <!-- this section contains meta information --> <p>reviews: good</p> <p>updated: yesterday</p> </article>

The count() function is a great way to navigate bare HTML trees that otherwise might appear unparsable.

Scale Your Web Scraping
Anti-bot bypass, browser rendering, and rotating proxies — all in one API. Start with 1,000 free credits.
No credit card required 1,000 free API credits Anti-bot bypass included
Not ready? Get our newsletter instead.