# Colly

> A fast, clean scraping framework for building web crawlers in Go

- Category: Data & Labeling / Web Scraping & Crawling
- Language: Go
- Repository: https://github.com/gocolly/colly
- Website: https://go-colly.org
- Canonical page: https://ai-tldr.dev/tools/colly/

## In short

Colly is a scraping framework for the Go programming language. It gives you a clean API to write crawlers, scrapers, and spiders that pull structured data out of websites. It sits in the Web Scraping & Crawling category of the Data & Labeling tools and is open-source, written in Go.

## Overview

Colly is a scraping framework for the Go programming language. It gives you a clean API to write crawlers, scrapers, and spiders that pull structured data out of websites.

It is aimed at Go developers who need to collect data at scale for jobs like data mining, data processing, or archiving. You attach callbacks to events such as a request being made or an HTML element being found, and Colly handles the crawling loop for you.

As a web scraping and crawling tool, Colly covers the common needs of production crawlers: per-domain request delays and concurrency limits, automatic cookie and session handling, caching, robots.txt support, and synchronous, asynchronous, or parallel scraping.

## What it does

- Clean API for writing crawlers, scrapers, and spiders
- Fast: over 1k requests per second on a single core
- Manages request delays and maximum concurrency per domain
- Automatic cookie and session handling
- Sync, async, and parallel scraping modes
- Caching, robots.txt support, and distributed scraping

## Getting started

Add Colly to a Go module, then register callbacks on a collector and start visiting pages.

1. Install Colly

   Fetch the v2 module with go get inside your Go project.

```bash
go get github.com/gocolly/colly/v2
```

2. Crawl a page and follow its links

   Create a collector, attach an OnHTML callback to follow links and an OnRequest callback to log each visit, then call Visit to start.

```go
import (
	"fmt"

	"github.com/gocolly/colly/v2"
)

func main() {
	c := colly.NewCollector()

	// Find and visit all links
	c.OnHTML("a[href]", func(e *colly.HTMLElement) {
		e.Request.Visit(e.Attr("href"))
	})

	c.OnRequest(func(r *colly.Request) {
		fmt.Println("Visiting", r.URL)
	})

	c.Visit("http://go-colly.org/")
}
```

3. Explore more examples

   See the _examples folder in the repository for more detailed, runnable scrapers.

## When to use it

- Crawling a website and following its internal links to map or archive its pages
- Extracting structured data from HTML for data mining or processing pipelines
- Running large-scale collection with per-domain rate limits and concurrency control
- Building async or distributed scrapers that handle cookies and caching automatically
