Skip to content

cheeriovshtmlquery

MIT 40 13 30,265
80.4 million (month) Oct 08 2011 1.2.0(2026-02-21 19:30:40 ago)
781 1 8 MIT
Feb 07 2019 58.1 thousand (month) v1.3.6(2026-03-06 04:46:15 ago)

cheerio is a popular JavaScript library that allows you to interact with and manipulate HTML and XML documents in a similar way to how you would with jQuery in a browser. It is a fast, flexible, and lean implementation of core jQuery designed specifically for the server.

One of the main benefits of using cheerio is that it allows you to use jQuery-like syntax to navigate and m anipulate the Document Object Model (DOM) of an HTML or XML document, making it easy to work with.

cheerio supports CSS selectors though not XPath.

htmlquery is a Go library that allows you to parse and extract data from HTML documents using XPath expressions. It provides a simple and intuitive API for traversing and querying the HTML tree structure, and it is built on top of the popular Goquery library.

Example Use


```javascript const cheerio = require('cheerio'); const $ = cheerio.load('My title

Hello World!

'); // use css selectors console.log($('title').text()); // My title console.log($('.name').text()); // Hello World! // select multiple elements const $ = cheerio.load('
  • item 1
  • item 2
'); $('li').each(function(i, elem) { console.log($(this).text()); }); // modify elements const $ = cheerio.load('

Hello World!

'); $('h1').text('Hello, Cheerio!'); console.log($.html()); ```
```go package main import ( "fmt" "log" "github.com/antchfx/htmlquery" ) func main() { // Parse the HTML string doc, err := htmlquery.Parse([]byte(`

Hello, World!

  • Item 1
  • Item 2
  • Item 3
`)) if err != nil { log.Fatal(err) } // Extract the text of the first

element h1 := htmlquery.FindOne(doc, "//h1") fmt.Println(htmlquery.InnerText(h1)) // "Hello, World!" // Extract the text of all
  • elements lis := htmlquery.Find(doc, "//li") for _, li := range lis { fmt.Println(htmlquery.InnerText(li)) } // "Item 1" // "Item 2" // "Item 3" } ```
  • Alternatives / Similar


    Was this page helpful?