     [Answers](https://scrapfly.io/blog)   /  [css-selectors](https://scrapfly.io/blog/tag/css-selectors)   /  [How to use CSS Selectors in Nim ?](https://scrapfly.io/blog/answers/how-to-use-css-selectors-in-nim)   # How to use CSS Selectors in Nim ?

 by [Bernardas Alisauskas](https://scrapfly.io/blog/author/bernardas) Apr 16, 2024 1 min read [\#css-selectors](https://scrapfly.io/blog/tag/css-selectors) 

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

 

 

To parse web scraped content in Nim using CSS selectors we recommend the [CSS3Selectors](https://github.com/Niminem/CSS3Selectors) library which is designed with web scraping in mind:

nim```nim
import std/streams
import pkg/chame/minidom
import css3selectors

let html = """
    
    <html>
    <head><title>Example</title></head>
    <body>
        <p>1</p>
        <p>2</p>
        <p>3</p>
        <p>4</p>
    </body>
    </html>
    """
let document = Node(parseHtml(newStringStream(html)))
let elements = document.querySelectorAll("p:nth-child(odd)")
echo elements # @[<p>1</p>, <p>3</p>]

let htmlFragment = parseHTMLFragment("<h1 id='test'>Hello World</h1><h2>Test Test</h2>", Element())
let element = htmlFragment.querySelector("#test")
echo element # <h1 id="test">Hello World</h1>
```



CSS3Selectors was created to supersede [nimquery](https://github.com/GULPF/nimquery/) which still works well for parsing HTML content in Nim if CSS3Selectors is not available:

nim```nim
from xmltree import `$`
from htmlparser import parseHtml
import nimquery

let html = """

<html>
  <head><title>Example</title></head>
  <body>
    <p>1</p>
    <p>2</p>
    <p>3</p>
    <p>4</p>
  </body>
</html>
"""
let xml = parseHtml(html)
let elements = xml.querySelectorAll("p:nth-child(odd)")
echo elements
# => @[<p>1</p>, <p>3</p>]
```





 

    



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-use-css-selectors-in-nim) [ Gemini ](https://www.google.com/search?udm=50&aep=11&q=Summarize%20this%20page%3A%20https%3A%2F%2Fscrapfly.io%2Fblog%2Fanswers%2Fhow-to-use-css-selectors-in-nim) [ Grok ](https://x.com/i/grok?text=Summarize%20this%20page%3A%20https%3A%2F%2Fscrapfly.io%2Fblog%2Fanswers%2Fhow-to-use-css-selectors-in-nim) [ Perplexity ](https://www.perplexity.ai/search/new?q=Summarize%20this%20page%3A%20https%3A%2F%2Fscrapfly.io%2Fblog%2Fanswers%2Fhow-to-use-css-selectors-in-nim) [ Claude ](https://claude.ai/new?q=Summarize%20this%20page%3A%20https%3A%2F%2Fscrapfly.io%2Fblog%2Fanswers%2Fhow-to-use-css-selectors-in-nim) 



 ## Related Articles

 [  

 data-parsing css-selectors 

### Parsing HTML with CSS Selectors

Introduction to using CSS selectors to parse web-scraped content. Best practices, available tools and common challenges ...

 

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

 http python 

### How to Scrape in Another Language, Currency or Location

Localization allows for adapting websites content by changing language and currency. So, how do we scrape it? We'll take...

 

 ](https://scrapfly.io/blog/posts/how-to-scrape-in-another-language-or-currency) [  

 python data-parsing 

### How to Parse XML

In this article, we'll explain about XML parsing. We'll start by defining XML files, their format and how to navigate th...

 

 ](https://scrapfly.io/blog/posts/how-to-parse-xml) 

  ## Related Questions

- [ Q How to use CSS Selectors in Python? ](https://scrapfly.io/blog/answers/how-to-use-css-selectors-in-python)
- [ Q How to use CSS selectors in NodeJS when web scraping? ](https://scrapfly.io/blog/answers/how-to-use-css-selectors-in-nodejs)
- [ Q XPath vs CSS selectors: what's the difference? ](https://scrapfly.io/blog/answers/xpath-vs-css-selectors)
- [ Q How to select HTML elements by text using CSS Selectors? ](https://scrapfly.io/blog/answers/how-to-select-elements-by-text-using-css-selectors)
 
  



   



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