     [Answers](https://scrapfly.io/blog)   /  [xpath](https://scrapfly.io/blog/tag/xpath)   /  [How to count selections in XPath and why?](https://scrapfly.io/blog/answers/how-to-count-selectors-in-xpath-and-why)   # How to count selections in XPath and why?

 by [Bernardas Alisauskas](https://scrapfly.io/blog/author/bernardas) Apr 19, 2023 1 min read [\#xpath](https://scrapfly.io/blog/tag/xpath) 

 [  ](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fscrapfly.io%2Fblog%2Fanswers%2Fhow-to-count-selectors-in-xpath-and-why "Share on LinkedIn")    

 

 

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:

&lt;!-- select only paragraphs related to product data but not metadata --&gt; &lt;article&gt; &lt;h2&gt;Data&lt;/h2&gt; &lt;!-- this section contains product information --&gt; &lt;p&gt;price: 199&lt;/p&gt; &lt;p&gt;year: 2023&lt;/p&gt; &lt;h2&gt;Data&lt;/h2&gt; &lt;!-- this section contains meta information --&gt; &lt;p&gt;reviews: good&lt;/p&gt; &lt;p&gt;updated: yesterday&lt;/p&gt; &lt;/article&gt; The `count()` function is a great way to navigate bare HTML trees that otherwise might appear unparsable.



 

   Table of Contents















 

   Join the Newsletter  Get monthly web scraping insights 

 

  



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 

 [Start Free](https://scrapfly.io/register) [View Docs](https://scrapfly.io/docs/onboarding) 

 Not ready? Get our newsletter instead. 

 

## Explore this Article with AI

 [ ChatGPT ](https://chat.openai.com/?q=Summarize%20this%20page%3A%20https%3A%2F%2Fscrapfly.io%2Fblog%2Fanswers%2Fhow-to-count-selectors-in-xpath-and-why) [ Gemini ](https://www.google.com/search?udm=50&aep=11&q=Summarize%20this%20page%3A%20https%3A%2F%2Fscrapfly.io%2Fblog%2Fanswers%2Fhow-to-count-selectors-in-xpath-and-why) [ Grok ](https://x.com/i/grok?text=Summarize%20this%20page%3A%20https%3A%2F%2Fscrapfly.io%2Fblog%2Fanswers%2Fhow-to-count-selectors-in-xpath-and-why) [ Perplexity ](https://www.perplexity.ai/search/new?q=Summarize%20this%20page%3A%20https%3A%2F%2Fscrapfly.io%2Fblog%2Fanswers%2Fhow-to-count-selectors-in-xpath-and-why) [ Claude ](https://claude.ai/new?q=Summarize%20this%20page%3A%20https%3A%2F%2Fscrapfly.io%2Fblog%2Fanswers%2Fhow-to-count-selectors-in-xpath-and-why) 



 ## Related Articles

 [  

 python data-parsing 

### Parsing HTML with Xpath

Introduction to xpath in the context of web-scraping. How to extract data from HTML documents using xpath, best practice...

 

 ](https://scrapfly.io/blog/posts/parsing-html-with-xpath) [  

 python data-parsing 

### Web Scraping Phone Numbers with Python

In this article we'll dive into phone number scraping. We'll explore an example object and cover common phone number scr...

 

 ](https://scrapfly.io/blog/posts/how-to-scrape-phone-numbers-with-python) [  

 data-parsing xpath 

### Ultimate XPath Cheatsheet for HTML Parsing in Web Scraping

Ultimate companion for HTML parsing using XPath selectors. This cheatsheet contains all syntax explanations with interac...

 

 ](https://scrapfly.io/blog/posts/xpath-cheatsheet) 

  ## Related Questions

- [ Q How to get the name of an HTML element in XPath? ](https://scrapfly.io/blog/answers/how-to-get-name-of-selected-element-in-xpath)
- [ Q How to select elements by class in XPath? ](https://scrapfly.io/blog/answers/how-to-select-elements-by-class-in-xpath)
- [ Q How to reverse expressions in XPath? ](https://scrapfly.io/blog/answers/how-to-reverse-expression-in-xpath)
- [ Q How to select sibling elements in XPath? ](https://scrapfly.io/blog/answers/how-to-select-sibling-elements-using-xpath)
 
  



   



 Scale your web scraping effortlessly, **1,000 free credits** [Start Free](https://scrapfly.io/register)