需自行安装 Go 工具链并初始化模块;README 未说明默认端口或其他额外依赖
go get github.com/gocolly/colly/v2README 未说明,纯 Go 库,无 GPU 或显存要求
Go 语言写的爬虫与抓取框架,用干净接口快速从网站提取结构化数据
Go 语言编写的高性能网页抓取与爬虫框架,提供简洁 API 处理请求、解析页面和并发抓取,适合快速搭建采集程序。
核心能力
- 用 OnHTML 回调按 CSS 选择器提取页面数据
- 按域名管理请求延迟与最大并发数
- 自动处理 Cookie 与 Session
- 支持同步、异步与并行抓取
- 内置缓存、robots.txt 支持与分布式抓取
容易踩的坑
- v2.2.0最新正式版2025-03-27 · 2025-03-27 10:47 UTC
Tons of bug fixes & little improvements & updated dependencies
What's Changed
- Added new project that uses Colly by @twiny in https://github.com/gocolly/colly/pull/525
- adding docker-slim to the list of open source projects using Colly by @kcq in https://github.com/gocolly/colly/pull/526
- update coursera example by @ysung6 in https://github.com/gocolly/colly/pull/537
- Update openedx_courses.go by @lingt-xyz in https://github.com/gocolly/colly/pull/539
- feat: support Stop() in queue by @PalanQu in https://github.com/gocolly/colly/pull/531
- Fix invalid base URL assignment by @dasshield in https://github.com/gocolly/colly/pull/549
- Add context.Context support by @WGH- in https://github.com/gocolly/colly/pull/548
- Fix handling of redirected URLs in OnResponseHeaders by @WGH- in https://github.com/gocolly/colly/pull/561
- Fix race on count fields of Collector type by @shubham14bajpai in https://github.com/gocolly/colly/pull/563
- SetProxyFunc: fix proxies rotation by @wowinter13 in https://github.com/gocolly/colly/pull/567
- Update xkcd_store.go by @BigManing in https://github.com/gocolly/colly/pull/570
- Updated xmlquery to close a known security vulnerability by @ijomeli in https://github.com/gocolly/colly/pull/582
- Fix default User-Agent when using custom headers by @WGH- in https://github.com/gocolly/colly/pull/592
- Update openedx_courses.go by @BigManing in https://github.com/gocolly/colly/pull/576
- Add httpBackend cache response callback by @slashapp in https://github.com/gocolly/colly/pull/574
- Update README.md by @seversky in https://github.com/gocolly/colly/pull/595
- Change the type assersion for Attr by @moritamori in https://github.com/gocolly/colly/pull/588
- Update User-Agent strings for Desktop by @guessi in https://github.com/gocolly/colly/pull/605
- add quote crawler using colly by @eval-exec in https://github.com/gocolly/colly/pull/603
- Fix golint issues by @waltton in https://github.com/gocolly/colly/pull/620
- Replace Travis with GitHub Actions by @alexhraber in https://github.com/gocolly/colly/pull/669
- Use github.com/nlnwa/whatwg-url for URL parsing by @WGH- in https://github.com/gocolly/colly/pull/673
- Fix Async ignoring its arguments by @ljbink in https://github.com/gocolly/colly/pull/652
- fix: generated code has compile error by @darjun in https://github.com/gocolly/colly/pull/629
- moving filterings to one function (checkFilters) and use it in case of redirect too by @joelazar in https://github.com/gocolly/colly/pull/638
- Fix Contributing.md link by @SaladinoBelisario in https://github.com/gocolly/colly/pull/641
- Work around invalid URL encoding in path by @WGH- in https://github.com/gocolly/colly/pull/675
- Host & Custom Header Support by @ErikOwen in https://github.com/gocolly/colly/pull/691
- Code cleanup by @WGH- in https://github.com/gocolly/colly/pull/678
- Add GitHub issue templates and nudge questions to Stack Overflow by @WGH- in https://github.com/gocolly/colly/pull/702
- Fix redirects ignoring AllowURLRevisit=false by @WGH- in https://github.com/gocolly/colly/pull/681
- Bump whatwg-url version by @WGH- in https://github.com/gocolly/colly/pull/713
- fix some typos by @cuishuang in https://github.com/gocolly/colly/pull/736
- feat: Add MaxRequests paramete by @guilhem in https://github.com/gocolly/colly/pull/722
- Update CI configuration by @WGH- in https://github.com/gocolly/colly/pull/749
- upgrade Cascadia version by @kinoute in https://github.com/gocolly/colly/pull/650
- Bump golang.org/x/net from 0.0.0-20220114011407-0dd24b26b47d to 0.7.0 by @dependabot in https://github.com/gocolly/colly/pull/756
- Support websites redirecting to the same page when AllowURLRevisit is disabled by @WGH- in https://github.com/gocolly/colly/pull/763
- Update User-Agent strings for 2023 by @guessi in https://github.com/gocolly/colly/pull/765
- Fix data races by @WGH- in https://github.com/gocolly/colly/pull/771
- Replaced deprecated io/ioutil packa
- v2.1.02020-06-08 · 2020-06-08 23:47 UTC
查看更新说明
- HTTP tracing support
- New callback: OnResponseHeader
- Queue fixes
- New collector option: Collector.CheckHead
- Proxy fixes
- Fixed POST revisit checking
- Updated dependencies
- v2.0.02019-11-28 · 2019-11-28 12:29 UTC
查看更新说明
- Breaking change: Change Collector.RedirectHandler member to Collector.SetRedirectHandler function
- Go module support
- Collector.HasVisited method added to be able to check if an url has been visited
- Collector.SetClient method introduced
- HTMLElement.ChildTexts method added
- New user agents
- Multiple bugfixes
- v1.2.02019-02-13 · 2019-02-13 13:20 UTC
查看更新说明
- Compatibility with the latest htmlquery package
- New request shortcut for HEAD requests
- Check URL availibility before visiting
- Fix proxy URL value
- Request counter fix
- Minor fixes in examples
- v1.1.02018-08-28 · 2018-08-28 16:55 UTC
查看更新说明
- Appengine integration takes context.Context instead of http.Request (API change)
- Added "Accept" http header by default to every request
- Support slices of pointers and structs in unmarshal
- Fixed a race condition in queues
- ForEachWithBreak method added to HTMLElement
- Added a local file example
- Support gzip decompression of response bodies
- Don't share waitgroup when cloning a collector
- Fixed instagram example
用户点评
登录用户的真实使用记录,可按版本和硬件筛选还没有人点评。第一个说出真实体验的人最有价值。
Colly
Lightning Fast and Elegant Scraping Framework for Gophers
Colly provides a clean interface to write any kind of crawler/scraper/spider.
With Colly you can easily extract structured data from websites, which can be used for a wide range of applications, like data mining, data processing or archiving.
Sponsors
NodeMaven: The most efficient proxy provider for Web Scrapping and Automation with the Highest Quality IP on the market.
Why NodeMaven?
- 99.9% uptime
- ZIP Targeting
- IP filtering: all proxies have fraud score <97%
- No KYC required
- Unique free tools: Proxy Bandwidth Checker, Meta Tag Checker, IP Lookup and others!
Special codes for Colly users:
- COLLY35 - 35% off to Mobile and Residential Proxies
- COLLY40 - 40% off to ISP (Static) Proxies
SerpApi: Web Search API for your AI apps
Access real-time data from search engines such as Google, Bing, YouTube, Amazon, and more in structured JSON or Markdown results via a simple API
SX.ORG: High-Speed High-Trust Proxies Built for Scraping & Automation at Any Scale
- 240+ Locations to choose from
- 120M+ IPs - Clean & Frequently Refreshed
- All proxy types: mobile, residential, data-center
- Extremely High-Trust - secure from bans
- Flexible pricing –pay-as-you-goor unlimited trafficoptions
Free trialfor new users - use promocode COLLY to claim 3GB of proxy
Features
- Clean API
- Fast (>1k request/sec on a single core)
- Manages request delays and maximum concurrency per domain
- Automatic cookie and session handling
- Sync/async/parallel scraping
- Caching
- Automatic encoding of non-unicode responses
- Robots.txt support
- Distributed scraping
- Configuration via environment variables
- Extensions
Example
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/")
}
See examples folder for more detailed examples.
Installation
go get github.com/gocolly/colly/v2
Bugs
Bugs or suggestions? Visit the issue tracker or join #colly on freenode
Other Projects Using Colly
Below is a list of public, open source projects that use Colly:
- greenpeace/check-my-pages Scraping script to test the Spanish Greenpeace web archive.
- altsab/gowap Wappalyzer implementation in Go.
- jesuiscamille/goquotes A quotes scraper, making your day a little better!
- jivesearch/jivesearch A search engine that doesn't track you.
- Leagify/colly-draft-prospects A scraper for future NFL Draft prospects.
- lucasepe/go-ps4 Search playstation store for your favorite PS4 games using the command line.
- yringler/inside-chassidus-scraper Scrapes Rabbi Paltiel's web site for lesson metadata.
- gamedb/gamedb A database of Steam games.
- lawzava/scrape CLI for email scraping from any website.
- eureka101v/WeiboSpiderGo A sina weibo(chinese twitter) scraper
- Go-phie/gophie Search, Download and Stream movies from your terminal
- imthaghost/goclone Clone websites to your computer within seconds.
- superiss/spidy Crawl the web and collect expired domains.
- docker-slim/docker-slim Optimize your Docker containers to make them smaller and better.
- seversky/gachifinder an agent for asynchronous scraping, parsing and writing to some storages(elasticsearch for now)
- eval-exec/goodreads crawl all tags and all pages of quotes from goodreads.
If you are using Colly in a project please send a pull request to add it to the list.
Contributors
This project exists thanks to all the people who contribute. [Contribute].
Backers
Thank you to all our backers! 🙏 [Become a backer]
Sponsors
Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [Become a sponsor]


