Connect Colly to one rotating proxy gateway.
Connect Colly to one rotating proxy gateway. This example uses Rotating Proxies as the default gateway and can be adapted by replacing endpoint and routing credentials.
Install the client and create a file.
Use a clean project environment and pin tested dependency versions for production. The example target is a public scraping sandbox.
go get github.com/gocolly/colly/v2Load proxy secrets from the environment.
The proxy username is not the LundProxy website login. Copy the complete username and password generated for the selected proxy product.
PROXY_USER=user-pool-crawlerPROXY_PASS=your-secretmain.go
Copy the code into the named file, set credentials, and run it from the project environment.
package main
import (
"fmt"
"net/url"
"os"
"time"
"github.com/gocolly/colly/v2"
"github.com/gocolly/colly/v2/proxy"
)
func main() {
gateway := &url.URL{
Scheme: "http",
Host: "proxy.lundproxy.com:36923",
User: url.UserPassword(os.Getenv("PROXY_USER"), os.Getenv("PROXY_PASS")),
}
switcher, err := proxy.RoundRobinProxySwitcher(gateway.String())
if err != nil { panic(err) }
collector := colly.NewCollector(
colly.AllowedDomains("quotes.toscrape.com"),
)
collector.SetProxyFunc(switcher)
collector.SetRequestTimeout(30 * time.Second)
collector.OnHTML(".quote", func(element *colly.HTMLElement) {
fmt.Println(element.ChildText(".author"))
})
if err := collector.Visit("https://quotes.toscrape.com/"); err != nil {
panic(err)
}
}
Keep the important behavior visible.
Add workload-specific controls before scale.
Test representative targets, response sizes, routing policy, concurrency, retries, validation, and completion window. Collect only public data you are authorized to access.
Colly questions.
Why use a switcher with one gateway?
Colly expects a proxy function; LundProxy performs exit rotation behind the fixed gateway.
How do I add concurrency?
Use Colly limits and async mode gradually while measuring target responses.
Where should errors be logged?
Use OnError to record URL, status, attempt, and route policy.