Colly
Fast and elegant scraping framework for Go with callbacks, async crawling and rate limiting.
Official Documentation ↗colly v2 / Go 1.20+. Check the official docs for the latest API surface.Installation
go get github.com/gocolly/collyMethods
No methods match this filter.
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(取到逐字声明).
colly.NewCollector→ signature from https://raw.githubusercontent.com/gocolly/colly/v2.3.0/colly.go; official text: “// NewCollector creates a new Collector instance with default configuration func NewCollector(options …CollectorOption) *Collector {”collector.OnHTML→ signature from https://raw.githubusercontent.com/gocolly/colly/v2.3.0/colly.go; official text: “// GoQuery Selector is a selector used by https://github.com/PuerkitoBio/goquery func (c *Collector) OnHTML(goquerySelector string, f HTMLCallback) {”collector.Visit / Limit→ signature from https://raw.githubusercontent.com/gocolly/colly/v2.3.0/colly.go; official text: “// Visit also calls the previously provided callbacks func (c *Collector) Visit(URL string) error { // Limit adds a new LimitRule to the collector func (c *Collector) Limit(rule *LimitRule) error {”
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.
Report a problem with this API docOpens a pre-filled issue on GitHub.