API Reference

Colly

Fast and elegant scraping framework for Go with callbacks, async crawling and rate limiting.

Official Documentation ↗
CompatibilityThis documentation covers version colly v2 / Go 1.20+. Check the official docs for the latest API surface.

Installation

gogo get github.com/gocolly/colly

Methods

Overview

Colly is a scraping framework that models crawling as a collector with callbacks. It handles visiting, following links, async concurrency and polite rate limiting.

Core Methods

Create a collector, register OnHTML, OnRequest and OnError callbacks, set limits, then visit seed URLs. In async mode, call Wait to block until crawling completes.

Usage Notes

Restrict domains, set a delay and parallelism, and follow links from callbacks to keep the crawl scoped. Always Wait in async mode to avoid premature exit.

Common Pitfalls

Without domain restrictions the crawler can wander and never finish. No delay triggers bans. Forgetting Wait in async mode ends the process mid-crawl and loses data.

API reference evidence

Fetched from official sources on 2026-11-08T19:05:00+08:00 via WebFetch https://pkg.go.dev/github.com/gocolly/colly/v2(索引部分被截断);PowerShell Invoke-WebRequest https://raw.githubusercontent.com/gocolly/colly/v2.3.0/colly.go(取到逐字声明).

FAQ

How do I crawl asynchronously?
Enable Async(true) and then wait on c.Wait() after visiting seeds, so the program does not exit before in-flight requests finish.
How do I respect robots and rate limits?
Set AllowedDomains and LimitRule with a delay and parallelism, and check robots rules or honor the site policy to avoid being blocked.
How are errors handled?
Register OnError to receive failed requests and decide whether to retry. Colly also lets you set retry limits and status code handling through callbacks.