Go is a good fit for scraping for one reason: cheap concurrency with explicit control over how much of it you use. That same property is what makes a careless Go scraper worse than a careless Python one, because thousands of simultaneous requests are two lines away.
This guide covers the standard-library approach, the concurrency pattern worth copying, proxy and timeout wiring, and the point at which a framework earns its place.
Key Facts
- Go’s advantage is concurrency you can bound. Goroutines are cheap, which is exactly why an unbounded scraper written in Go hurts the target faster than one in Python.
- The standard library covers most of it. net/http plus one HTML parser handles the majority of scraping work without a framework.
- Always set a context deadline. A request without one can hang for the life of the process, and one stuck goroutine quietly becomes thousands.
- Reuse the client, never the request. One http.Client with a configured Transport gives you connection pooling; a new client per request throws it away.
- Go does not render JavaScript. For pages that build themselves in the browser you need a headless browser, not a better parser.
What does a minimal Go scraper look like?
Three pieces: a reused client, a request with a context, and a parser.
client := &http.Client{
Timeout: 30 * time.Second,
Transport: &http.Transport{
MaxIdleConns: 100,
MaxIdleConnsPerHost: 10,
IdleConnTimeout: 90 * time.Second,
},
}
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
defer cancel()
req, _ := http.NewRequestWithContext(ctx, "GET", target, nil)
req.Header.Set("User-Agent", ua)
resp, err := client.Do(req)
if err != nil { return err }
defer resp.Body.Close()
doc, err := goquery.NewDocumentFromReader(resp.Body)
Two details carry most of the value. The client is created once and shared, which is what gives you connection reuse; creating one per request is the single most common performance mistake in Go scrapers. And defer resp.Body.Close() is not optional: skip it and connections leak until the pool is exhausted and everything stalls with no error that points at the cause.
How do you run it concurrently without hurting the target?
With a bounded worker pool, never with a goroutine per URL. We call it the 4-part concurrency model.
| Part | What it controls | Failure without it |
|---|---|---|
| 1. Fixed worker count | How many requests are in flight at once | Unbounded goroutines flood the target and exhaust local sockets |
| 2. Per-host limit | Concurrency against any single domain | One domain absorbs the whole pool and gets hammered |
| 3. Rate limiter | Requests per second, independent of worker count | Ten workers still means a burst of ten |
| 4. Context cancellation | How work stops | Shutdown leaves goroutines running and results half written |
sem := make(chan struct{}, 10) // 10 concurrent
limiter := time.NewTicker(200 * time.Millisecond) // 5 req/sec
defer limiter.Stop()
var wg sync.WaitGroup
for _, u := range urls {
wg.Add(1)
go func(u string) {
defer wg.Done()
sem <- struct{}{}
defer func() { <-sem }()
<-limiter.C
fetch(ctx, client, u)
}(u)
}
wg.Wait()
The rate limiter is the part people drop, and it is the one that decides whether you look like a visitor or an incident. Worker count caps parallelism; the ticker caps throughput. You want both.
How do you wire proxies and retries?
Proxies attach to the Transport, which means a proxy per client rather than per request.
proxyURL, _ := url.Parse("http://USER:[email protected]:823")
transport := &http.Transport{
Proxy: http.ProxyURL(proxyURL),
MaxIdleConnsPerHost: 10,
}
client := &http.Client{Transport: transport, Timeout: 30 * time.Second}
Because the proxy is bound to the client, rotation is done by keeping a small pool of clients rather than by rewriting one. That also keeps connection reuse intact per exit, which matters more for throughput than the rotation itself.
For retries, three rules keep a scraper honest. Retry only idempotent failures: connection errors, timeouts, 429 and 5xx. Back off exponentially with jitter rather than on a fixed interval, because fixed retries from many workers resynchronise into a burst. And honour Retry-After when the server sends it, since that is the site telling you exactly what it wants.
When is the standard library not enough?
| Situation | Use this when | Avoid when |
|---|---|---|
| Fetch and parse static HTML | net/http plus goquery | You need crawling policy, queues and callbacks |
| Crawling with depth rules and dedup | A framework like Colly | You have five URLs; the framework is overhead |
| Page builds itself with JavaScript | A headless browser driver | The data is in the HTML or an underlying API |
| Site exposes a JSON endpoint | Call it directly | Never render a page to reach data the page fetches |
| Heavy anti-bot protection | Reconsider the approach | You assume more concurrency will help; it will not |
The fourth row is worth checking first on every project. A page that renders a table from an API call can be read from that API with one request instead of a browser, and Go is particularly good at that kind of work.
For the framework route see our Golang Colly tutorial, which covers the collector lifecycle and rotation inside Colly specifically.
What bites in production?
Unclosed bodies. The failure is delayed and looks like a network problem rather than a bug in your code.
Missing deadlines. A request with no context timeout can hang indefinitely, and in a long-running scraper that quietly accumulates stuck goroutines until memory becomes the visible symptom.
Compression and encoding. Go handles gzip transparently only when it set the header itself; if you set Accept-Encoding by hand you own the decompression too. Character encoding also needs handling for pages that are not UTF-8.
Politeness. Honour robots.txt, keep per-host concurrency at one or two for smaller sites, and identify yourself where it is appropriate. Go makes it trivially easy to generate load that a small site experiences as an outage. General information rather than legal advice: see is web scraping legal and 403 Forbidden when scraping.
Frequently Asked Questions
Is Go good for web scraping?
Yes, particularly for high-volume fetching of static pages, because goroutines make concurrency cheap and the standard library covers HTTP well. The same cheapness is a hazard: a bounded worker pool and a rate limiter are mandatory, not optional refinements.
Do I need a framework for web scraping with Go?
Not for fetching and parsing, where net/http plus an HTML parser is enough. A framework earns its place when you need crawling policy: depth limits, URL deduplication, queueing and callback structure across many pages.
How do I use a proxy in a Go scraper?
Set Proxy on the http.Transport and reuse the client. Because the proxy binds to the transport, rotation means keeping a small pool of clients rather than rebuilding one, which also preserves connection reuse per exit.
Can Go scrape JavaScript-rendered pages?
Not on its own. Go fetches HTML and does not execute scripts, so a page that builds itself in the browser needs a headless browser driver. Check first whether the page calls an API you could request directly, which is faster and cheaper than rendering.
Why does my Go scraper slow down over time?
Most often unclosed response bodies exhausting the connection pool, or requests without context deadlines leaving goroutines stuck. Both present as network slowness rather than as an error pointing at the cause.
Exits that keep the pool warm
Rotation in Go works best as a pool of clients, each holding its own exit and its own connections. DataImpulse residential proxies cover 195 countries at $1 per GB with country, city and ZIP targeting. Create an account and wire one into your Transport.
Related: Golang Colly tutorial · proxy setup by language · proxies for web scraping.
Last updated: September 18, 2026.
