explaingit

puerkitobio/goquery

Analysis updated 2026-06-24

14,938GoAudience · developerComplexity · 2/5Setup · easy

TLDR

goquery brings jQuery-style CSS selectors and chaining to Go for reading and manipulating HTML documents, built on net/html and the cascadia selector engine.

Mindmap

mindmap
  root((goquery))
    Inputs
      HTML source
      CSS selectors
      io Reader
    Outputs
      Selections
      Extracted text
      Modified HTML
    Use Cases
      Web scraping
      HTML rewriting
      Test fixtures
      Feed parsing
    Tech Stack
      Go
      net html
      cascadia
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

What do people build with it?

USE CASE 1

Scrape titles and links from an HTML page using jQuery-style CSS selectors

USE CASE 2

Walk a Selection with EachIter and Go range syntax to process matched nodes

USE CASE 3

Rewrite a parsed HTML document with AppendHtml or AfterHtml and Render the result to an io.Writer

USE CASE 4

Pre-compile a cascadia selector once and reuse it across many goquery calls for speed

What is it built with?

Gonet/htmlcascadia

How does it compare?

puerkitobio/goqueryhoanhan101/ultimate-goloft-sh/devpod
Stars14,93814,91014,900
LanguageGoGoGo
Setup difficultyeasyeasymoderate
Complexity2/51/53/5
Audiencedeveloperdeveloperops devops

Figures from each repo's GitHub metadata at analysis time.

How do you get it running?

Difficulty · easy Time to first run · 5min

Input must be UTF-8 and goquery v1.12 requires Go 1.25+, so older Go toolchains need an older goquery release.

In plain English

goquery is a Go library for reading and manipulating HTML documents using a syntax taken from jQuery, the long-popular JavaScript library for browser scripting. The README's tagline calls it "a little like that j-thing, only in Go." If you know jQuery, you can use familiar selector strings like #id.class, or div > a to find parts of an HTML page, then chain methods on the result to read attributes, change text, or rearrange elements. The library is widely used in Go for scraping and parsing HTML. Internally, goquery is built on top of Go's standard net/html parser and a separate library called cascadia, which handles the CSS-selector matching. The README notes one consequence of this choice: net/html only returns a node tree rather than a full browser-style DOM, so jQuery's stateful methods that depend on layout, like height() and css(), are not provided. Another constraint is that net/html requires UTF-8 input, so callers have to convert other encodings before handing the HTML to goquery, the project wiki points to options for this. The README is mostly an installation section and a long changelog. Required Go versions have moved up over time: version 1.12.0 of goquery needs Go 1.25 or newer, version 1.11.0 needs Go 1.24 or newer, and earlier versions trace back through 1.23, 1.18, and 1.1, with the recent jumps driven by dependency updates and the adoption of generics and iterator functions. The author tests against the latest two Go releases. Installation is the usual go get of the package, with optional commands shown for running unit tests and benchmarks. The changelog entries also describe how the API has grown. Highlights from the README include a generic Map function, an EachIter method that exposes a Selection as a Go range iterator, a Render function that writes a Selection back to an io.Writer, Single and SingleMatcher helpers for first-match selection, parsing HTML in the context of the container node for methods like AppendHtml and AfterHtml, and an AttrOr helper that returns a default when an attribute is missing. A note states that the API is now considered stable and will not break. The README also mentions Matcher-based variants of the selector methods, which accept a pre-compiled cascadia selector so callers can handle compilation errors directly and reuse compiled selectors.

Copy-paste prompts

Prompt 1
Show me a Go program that uses goquery to fetch a URL and print every h2 heading on the page
Prompt 2
Give me a goquery snippet that converts a non-UTF-8 HTML response to UTF-8 before parsing
Prompt 3
Explain the difference between Selection.Each and Selection.EachIter in goquery v1.12 with an example
Prompt 4
Write a goquery scraper that extracts product name, price, and image URL from a list of pages concurrently
Prompt 5
Help me migrate code from a pre-1.10 goquery API to use the Matcher-based selector variants

Frequently asked questions

What is goquery?

goquery brings jQuery-style CSS selectors and chaining to Go for reading and manipulating HTML documents, built on net/html and the cascadia selector engine.

What language is goquery written in?

Mainly Go. The stack also includes Go, net/html, cascadia.

How hard is goquery to set up?

Setup difficulty is rated easy, with roughly 5min to a first successful run.

Who is goquery for?

Mainly developer.

Open on GitHub → Explain another repo

This repo across BitVibe Labs

Verify against the repo before relying on details.