The Scrapingbypass Golang SDK is a high-performance wrapper built on top of go-resty/resty/v2. It is specifically optimized for bypassing advanced anti-bot systems like Cloudflare and Akamai while maintaining consistent TLS/JA3 fingerprints.
Installation
The SDK requires Go versions supported by go-resty/resty/v2. Install it via Go Modules:
go get github.com/scrapingbypass/golang-sdk
Basic Usage
Initialize the client using scrapingbypass.New(). You can configure the Apikey and Proxy directly in the code or via environment variables (CB_APIKEY, CB_PROXY, CB_APIHOST).
package main
import (
"fmt"
"github.com/scrapingbypass/golang-sdk/scrapingbypass"
)
func main() {
// Initialize config
config := scrapingbypass.BypassConfig{
Apikey: "YOUR_API_KEY",
}
client := scrapingbypass.New(config)
resp, err := client.R().
EnableTrace().
Get("https://httpbin.org/get")
if err != nil {
fmt.Println("Request Error:", err)
return
}
// X-Cb-Status returns the bypass status code
fmt.Printf("Status: %d, Bypass-Status: %s\n", resp.StatusCode(), resp.Header().Get("X-Cb-Status"))
fmt.Println(resp.String())
}
Implementing V2 (JS Challenge Bypass)
Use Scrapingbypass API V2 for targets protected by JavaScript challenges or Turnstile. To enable V2, set the Part parameter to "0".
package main
import (
"fmt"
"github.com/scrapingbypass/golang-sdk/scrapingbypass"
)
func main() {
client := scrapingbypass.New(scrapingbypass.BypassConfig{
Apikey: "YOUR_API_KEY",
Proxy: "http://user:pass@proxy-host:port",
Part: "0", // Required for V2 validation
})
// Target protected by Cloudflare WAF
resp, err := client.R().
Get("https://etherscan.io/accounts/label/lido")
if err != nil {
fmt.Println(err)
return
}
fmt.Println("Response Body:", resp.String())
}
Proxy Management
The NewProxy method provides a fluent interface for extracting and rotating dynamic or sticky residential proxies.
| Method | Description |
|---|---|
SetDynamic() | Configures the instance for dynamic proxy rotation. |
SetExpire(sec) | Sets the TTL (Time-To-Live) for sticky sessions in seconds. |
SetRegion(code) | Filters proxy exit nodes by ISO country code (e.g., "US", "DE"). |
Iterate(n) | Returns an iterator to fetch a fixed batch of proxies. |
Loop(n) | Returns a circular iterator for continuous proxy rotation. |
Example: Proxy Rotation and Extraction
func main() {
proxy, _ := scrapingbypass.NewProxy("username-res:password")
// Extract a 10-minute sticky proxy in the US
stickyProxy := proxy.Copy().SetExpire(600).SetRegion("US").String()
fmt.Println("Sticky Proxy:", stickyProxy)
// Batch extraction using an iterator
iterator := proxy.SetRegion("US").Iterate(5)
for iterator.HasNext() {
fmt.Println("Next Proxy:", iterator.Next())
}
}
Core Concepts & Account Management
Account Balance
Check your remaining credit balance programmatically:
balance, err := scrapingbypass.GetBalance("YOUR_API_KEY")
fmt.Println("Current Balance:", balance)
Redirection Handling
The SDK automatically handles HTTP redirects (301/302). Note that each redirected hop that passes through the Scrapingbypass engine consumes credits according to the API version used.
Authentication
Secure your Apikey by using the CB_APIKEY environment variable to avoid hardcoding credentials in your source code. You can manage your keys via the Scrapingbypass Dashboard.