All systems operational HTTP · HTTPS · SOCKS5 Global network
Documentation home Quickstart Engineering guides Code examples Global network Pricing Solutions overview Custom proxy pools Managed data scraping Contact Console
CODE EXAMPLE

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.

LanguageGo 1.22+FrameworkCollyGatewayRotating ProxiesFilemain.go
01
SETUP

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.

Installgo get github.com/gocolly/colly/v2
02
CREDENTIALS

Load 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-secret
03
COMPLETE EXAMPLE

main.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)
    }
}
04
WHAT THE EXAMPLE DOES

Keep the important behavior visible.

01net/url safely constructs credentials.
02AllowedDomains limits crawl scope.
03One gateway still allows network-side rotation.
04The request timeout is explicit.
05
PRODUCTION NOTES

Add workload-specific controls before scale.

A successful sandbox run proves integration, not production readiness.

Test representative targets, response sizes, routing policy, concurrency, retries, validation, and completion window. Collect only public data you are authorized to access.

06
EXAMPLE FAQ

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.