```yaml
product: AlterLab
title: "Ruby HTML Parsing Gem Like Cheerio: Nokogiri | AlterLab"
comparison_context: "AlterLab is an alternative to Firecrawl, ScrapingBee, and Bright Data."
source_url: https://alterlab.io/answers/ruby-html-parsing-gem-like-cheerio
```

# Ruby HTML Parsing Gems Like Cheerio for Node.js

## Short answer

### Is there a Ruby gem for HTML parsing like Cheerio in Node.js?

Yes: Nokogiri. Like Cheerio, it parses HTML into a document you query with CSS selectors through css and at_css, and it also supports XPath. Oga is a pure-Ruby alternative without native extensions. Neither runs JavaScript, so fetch rendered HTML from an API such as AlterLab when a page builds its content client-side.

## Step by step

1. 1
   ### Install Nokogiri
   Add `gem 'nokogiri'` to your Gemfile and run bundle install.
2. 2
   ### Parse the HTML
   Call Nokogiri::HTML(html) on the page body you downloaded.
3. 3
   ### Query with CSS selectors
   Use doc.css('h2.title') for many elements or doc.at_css('h1') for the first match, just as you would with Cheerio's $().

## Example

Ruby

```
require "net/http"
require "nokogiri"

html = Net::HTTP.get(URI("https://example.com/articles"))
doc = Nokogiri::HTML(html)

doc.css("h2.title").each do |node|
  puts node.text.strip
end
```

## Frequently Asked Questions

### Nokogiri or Oga?

Nokogiri is faster and far more widely used. Choose Oga only when you cannot install native extensions in your environment.

### How do I get JavaScript-rendered content in Ruby?

Fetch the rendered HTML from a rendering API, or drive a browser with Ferrum, then pass the HTML to Nokogiri.

## Read the full guide

[Ruby web scraping guide](https://alterlab.io/ruby-web-scraping-guide)

## Related answers

[Scraping a Web Page in C# with HtmlAgilityPack](https://alterlab.io/answers/csharp-htmlagilitypack-scrape-web-page)[Web Scraping in Java: Getting TV Show Data from Web Pages](https://alterlab.io/answers/java-web-scraping-tv-show-data)

## Try it with AlterLab

Send a URL, get the page back as HTML, markdown or JSON. Rendering, proxy rotation and retries are handled for you.

[View API docs](https://alterlab.io/docs/api/rest)

## Your first scrape. Sixty seconds.

Up to 5,000 free requests — about 5,000 direct fetch, 500 managed sessions or 250 full browser rendering requests. No credit card. 
Just a POST request.

terminal

curl -X POST https://api.alterlab.io/v1/scrape \

-H "X-API-Key: YOUR_KEY" \

-H "Content-Type: application/json" \

-d '{"url": "https://example.com", "formats": ["markdown"]}'

[Start building free](https://alterlab.io/signin)

No credit card required · Up to 5,000 free requests (about 5,000 direct fetch, 500 managed sessions or 250 full browser rendering requests) · Balance never expires