$ show gocolly/colly
Colly is a mature, high-performance web scraping framework for Go, providing a clean, callback-based API for crawling and extracting structured data from HTML and XML. It handles HTTP requests, session management, caching, robots.txt compliance, proxy rotation, rate limiting, and parallel scraping out of the box. The library is built around a Collector object that orchestrates configurable callbacks (OnRequest, OnResponse, OnHTML, OnXML, OnError, OnScraped) and supports chaining, context propagation, and request queueing for large-scale scraping jobs. The codebase is well-structured, thoroughly tested, and follows Go idioms, making it a reliable choice for production scraping tasks. It is not a data research project; it is a general-purpose scraping library.
The LLM identified 4 files worth highlighting for reuse:
Provides functions to attach random user-agent generation to a Collector via OnRequest. Implements realistic desktop and mobile user agent strings for multiple browsers (Firefox, Chrome, Edge, Opera) and devices (Pixel, Nexus). Demonstrates the extension pattern (function that takes a Collector and modifies its callbacks) and is reusable in any scraping project requiring user-agent rotation.
Implements a configurable request queue with a Storage interface, allowing multiple consumer goroutines to process requests concurrently. The InMemoryQueueStorage is the default backend, but custom storage backends (e.g., Redis, disk) can be plugged in by implementing the Storage interface. This decouples queue management from the scraping logic and is a clean, reusable pattern for rate-limited or distributed scraping.
Provides a RoundRobinProxySwitcher function that returns a ProxyFunc, rotating through a list of proxy URLs for each request. The implementation stores the proxy URL in the request context for later retrieval. This is a reusable component that can be used with any Go HTTP client or scraper needing proxy rotation.
Defines the Storage interface for persisting visited URLs and cookies, with an InMemoryStorage implementation. The interface is minimal and clean, allowing easy substitution with persistent backends (e.g., database, file). The StringifyCookies/UnstringifyCookies helpers are also reusable for cookie serialization.