### Make GET Request with CloudScraper in Go
Source: https://context7.com/romainmichau/cloudscraper_go/llms.txt
Shows how to perform an HTTP GET request using the CloudScraper client. It includes setting custom headers and sending the request to a specified URL. The response handling includes printing the status code, body, and headers.
```go
package main
import (
"fmt"
"github.com/RomainMichau/cloudscraper_go/cloudscraper"
)
func main() {
client, err := cloudscraper.Init(false, false)
if err != nil {
fmt.Printf("Error: %v\n", err)
return
}
// Simple GET request
headers := map[string]string{
"Authorization": "Bearer token123",
"X-Custom-Header": "value",
}
response, err := client.Get("https://www.facebook.com/anything/", headers, "")
if err != nil {
fmt.Printf("Request failed: %v\n", err)
return
}
fmt.Printf("Status: %d\n", response.Status)
fmt.Printf("Body: %s\n", response.Body)
fmt.Printf("Headers: %v\n", response.Headers)
}
```
--------------------------------
### Perform Simple GET and POST Requests with Cloudscraper Go
Source: https://github.com/romainmichau/cloudscraper_go/blob/master/readMe.md
This snippet demonstrates how to initialize the Cloudscraper Go client and perform basic HTTP GET and POST requests. It handles the response body, which is printed to the console. Dependencies include the 'cloudscraper_go' package.
```go
package main
import (
"github.com/RomainMichau/cloudscraper_go/cloudscraper"
)
func main() {
client, _ := cloudscraper.Init(false, false)
res, _ := client.Post("https://www.facebook.com/anything/", make(map[string]string), "")
res2, _ := client.Get("https://www.facebook.com/anything/", make(map[string]string), "")
print(res.Body)
print(res2.Body)
}
```
--------------------------------
### Make POST Request with CloudScraper in Go
Source: https://context7.com/romainmichau/cloudscraper_go/llms.txt
Illustrates how to execute an HTTP POST request using the CloudScraper client. This example demonstrates setting custom headers, including 'Content-Type', and providing a request body, typically in JSON format. It also shows how to process the server's response.
```go
package main
import (
"fmt"
"github.com/RomainMichau/cloudscraper_go/cloudscraper"
)
func main() {
client, err := cloudscraper.Init(false, false)
if err != nil {
fmt.Printf("Error: %v\n", err)
return
}
headers := map[string]string{
"Content-Type": "application/json",
"Authorization": "Bearer abc123",
}
body := `{"username": "user@example.com", "password": "secret"}`
response, err := client.Post("https://api.example.com/login", headers, body)
if err != nil {
fmt.Printf("POST request failed: %v\n", err)
return
}
fmt.Printf("Response Status: %d\n", response.Status)
fmt.Printf("Response Body: %s\n", response.Body)
}
```
--------------------------------
### Custom HTTP Request with Options in Go
Source: https://context7.com/romainmichau/cloudscraper_go/llms.txt
Provides an example of making custom HTTP requests (e.g., PUT, DELETE) with advanced options using CloudScraper. It allows configuring headers, request body, proxy, timeout, and redirect behavior for fine-grained control over the HTTP interaction.
```go
package main
import (
"fmt"
"github.com/Danny-Dasilva/CycleTLS/cycletls"
"github.com/RomainMichau/cloudscraper_go/cloudscraper"
)
func main() {
client, err := cloudscraper.Init(false, false)
if err != nil {
fmt.Printf("Error: %v\n", err)
return
}
options := cycletls.Options{
Headers: map[string]string{
"X-API-Key": "secret-key",
"Content-Type": "application/xml",
},
Body: `Test`,
Proxy: "http://proxy.company.com:8080",
Timeout: 10,
DisableRedirect: true,
UserAgent: "", // Will use CloudScraper's default
Ja3: "", // Will use CloudScraper's default
}
// PUT request
response, err := client.Do("https://api.example.com/resource/123", options, "PUT")
if err != nil {
fmt.Printf("Request failed: %v\n", err)
return
}
fmt.Printf("Status: %d\n", response.Status)
fmt.Printf("Body: %s\n", response.Body)
// DELETE request with different options
deleteOptions := cycletls.Options{
Headers: map[string]string{"Authorization": "Bearer token"},
Timeout: 5,
}
deleteResp, err := client.Do("https://api.example.com/resource/123", deleteOptions, "DELETE")
if err != nil {
fmt.Printf("Delete failed: %v\n", err)
return
}
fmt.Printf("Delete Status: %d\n", deleteResp.Status)
}
```
--------------------------------
### Make GET Request
Source: https://context7.com/romainmichau/cloudscraper_go/llms.txt
Performs an HTTP GET request to the specified URL. The request includes automatically applied browser fingerprints and custom headers to help bypass CloudFlare protections.
```APIDOC
## Make GET Request
Performs an HTTP GET request with automatically applied browser fingerprints and custom headers.
### Method
GET
### Endpoint
`client.Get(url string, headers map[string]string, cfClearance string)`
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Request Example
```go
package main
import (
"fmt"
"github.com/RomainMichau/cloudscraper_go/cloudscraper"
)
func main() {
client, err := cloudscraper.Init(false, false)
if err != nil {
fmt.Printf("Error: %v\n", err)
return
}
// Simple GET request
headers := map[string]string{
"Authorization": "Bearer token123",
"X-Custom-Header": "value",
}
response, err := client.Get("https://www.facebook.com/anything/", headers, "")
if err != nil {
fmt.Printf("Request failed: %v\n", err)
return
}
fmt.Printf("Status: %d\n", response.Status)
fmt.Printf("Body: %s\n", response.Body)
fmt.Printf("Headers: %v\n", response.Headers)
}
```
### Response
#### Success Response (200)
- **response.Status** (int) - The HTTP status code of the response.
- **response.Body** (string) - The response body content.
- **response.Headers** (map[string]string) - The response headers.
#### Response Example
```json
{
"Status": 200,
"Body": "...",
"Headers": {
"Content-Type": "text/html",
"Server": "cloudflare"
}
}
```
```
--------------------------------
### Reuse CloudScraper Client for Sequential Requests in Go
Source: https://context7.com/romainmichau/cloudscraper_go/llms.txt
Demonstrates reusing a single CloudScraper client instance for multiple sequential HTTP requests (GET, POST). This pattern helps maintain consistent browser fingerprints across a session, essential for interacting with CloudFlare-protected services.
```go
package main
import (
"fmt"
"github.com/RomainMichau/cloudscraper_go/cloudscraper"
)
func main() {
client, err := cloudscraper.Init(false, false)
if err != nil {
fmt.Printf("Error: %v\n", err)
return
}
// First request - GET homepage
homeResp, err := client.Get("https://www.example.com/", make(map[string]string), "")
if err != nil {
fmt.Printf("Homepage request failed: %v\n", err)
return
}
fmt.Printf("Homepage Status: %d\n", homeResp.Status)
// Second request - POST login with same fingerprint
loginHeaders := map[string]string{
"Content-Type": "application/x-www-form-urlencoded",
}
loginBody := "username=user&password=pass"
loginResp, err := client.Post("https://www.example.com/login", loginHeaders, loginBody)
if err != nil {
fmt.Printf("Login failed: %v\n", err)
return
}
fmt.Printf("Login Status: %d\n", loginResp.Status)
// Third request - GET protected resource
protectedHeaders := map[string]string{
"Cookie": "session=abc123",
}
dataResp, err := client.Get("https://www.example.com/data", protectedHeaders, "")
if err != nil {
fmt.Printf("Data request failed: %v\n", err)
return
}
fmt.Printf("Data Status: %d\n", dataResp.Status)
fmt.Printf("Data Body: %s\n", dataResp.Body)
}
```
--------------------------------
### Customize HTTP Requests with Cloudscraper Go and CycleTLS
Source: https://github.com/romainmichau/cloudscraper_go/blob/master/readMe.md
This example shows how to customize HTTP requests using Cloudscraper Go, integrating with CycleTLS for advanced options such as custom headers, request body, proxy, timeout, and redirect control. The `Do` method sends the request, and the response body is printed. Dependencies include 'cycletls' and 'cloudscraper_go'.
```go
package main
import (
"github.com/Danny-Dasilva/CycleTLS/cycletls"
"github.com/RomainMichau/cloudscraper_go/cloudscraper"
)
func main() {
client, _ := cloudscraper.Init(false, false)
options := cycletls.Options{
Headers: map[string]string{"my_custom_header": "header_value"},
Body: "",
Proxy: "proxy.company.com",
Timeout: 10,
DisableRedirect: true,
}
res, _ := client.Do("https://www.facebook.com/anything", options, "PUT")
print(res.Body)
}
```
--------------------------------
### Initialize CloudScraper Client in Go
Source: https://context7.com/romainmichau/cloudscraper_go/llms.txt
Demonstrates how to initialize the CloudScraper client in Go for both desktop and mobile browsers, with options for synchronous and asynchronous modes. It shows how to handle potential initialization errors and export the generated TLS fingerprints and user agent strings.
```go
package main
import (
"fmt"
"github.com/RomainMichau/cloudscraper_go/cloudscraper"
)
func main() {
// Initialize client for desktop browsers, synchronous mode
client, err := cloudscraper.Init(false, false)
if err != nil {
fmt.Printf("Failed to initialize client: %v\n", err)
return
}
// Initialize client for mobile browsers, asynchronous mode with workers
mobileClient, err := cloudscraper.Init(true, true)
if err != nil {
fmt.Printf("Failed to initialize mobile client: %v\n", err)
return
}
// Export the current settings (JA3, user agent, headers)
settings := client.ExportSettings()
fmt.Printf("JA3: %s\n", settings["ja3"])
fmt.Printf("User Agent: %s\n", settings["userAgent"])
}
```
--------------------------------
### Initialize CloudScraper Client
Source: https://context7.com/romainmichau/cloudscraper_go/llms.txt
Creates a new CloudScraper client instance with randomized browser fingerprints (JA3, user agent, and headers) to bypass CloudFlare protections. Supports initialization for desktop or mobile browsers, and synchronous or asynchronous modes.
```APIDOC
## Initialize CloudScraper Client
Creates a new CloudScraper client instance with randomized browser fingerprints (JA3, user agent, and headers) to bypass CloudFlare protections.
### Method
GET (Conceptual - initialization)
### Endpoint
`cloudscraper.Init(isMobile bool, isAsync bool)`
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Request Example
```go
package main
import (
"fmt"
"github.com/RomainMichau/cloudscraper_go/cloudscraper"
)
func main() {
// Initialize client for desktop browsers, synchronous mode
client, err := cloudscraper.Init(false, false)
if err != nil {
fmt.Printf("Failed to initialize client: %v\n", err)
return
}
// Initialize client for mobile browsers, asynchronous mode with workers
mobileClient, err := cloudscraper.Init(true, true)
if err != nil {
fmt.Printf("Failed to initialize mobile client: %v\n", err)
return
}
// Export the current settings (JA3, user agent, headers)
settings := client.ExportSettings()
fmt.Printf("JA3: %s\n", settings["ja3"])
fmt.Printf("User Agent: %s\n", settings["userAgent"])
}
```
### Response
#### Success Response (200)
- **client** (*cloudscraper.CloudScraper*) - The initialized client instance.
- **err** (*error*) - An error object if initialization fails.
#### Response Example
(No direct response example, but successful initialization returns a client object and nil error.)
```
--------------------------------
### Queue HTTP Requests Asynchronously with Go
Source: https://context7.com/romainmichau/cloudscraper_go/llms.txt
Queues multiple HTTP requests for asynchronous execution and reads responses from a channel. This method is useful for high-performance concurrent scraping. It requires the 'CycleTLS' and 'cloudscraper' Go packages.
```go
package main
import (
"fmt"
"github.com/Danny-Dasilva/CycleTLS/cycletls"
"github.com/RomainMichau/cloudscraper_go/cloudscraper"
)
func main() {
// Initialize with workers enabled (async mode)
client, err := cloudscraper.Init(false, true)
if err != nil {
fmt.Printf("Error: %v\n", err)
return
}
// Queue multiple requests
urls := []string{
"https://www.example.com/page1",
"https://www.example.com/page2",
"https://www.example.com/page3",
}
for _, url := range urls {
options := cycletls.Options{
Headers: map[string]string{
"X-Custom-Header": "value",
},
Timeout: 10,
DisableRedirect: true,
}
client.Queue(url, options, "GET")
}
// Retrieve response channel
respChannel := client.RespChan()
// Read responses as they complete
for i := 0; i < len(urls); i++ {
response := <-respChannel
fmt.Printf("Received response from: %s\n", response.FinalUrl)
fmt.Printf("Status: %d\n", response.Status)
fmt.Printf("Body length: %d bytes\n", len(response.Body))
if response.Status != 200 {
fmt.Printf("Error or non-200 status\n")
}
}
}
```
--------------------------------
### Custom HTTP Request with Options
Source: https://context7.com/romainmichau/cloudscraper_go/llms.txt
Executes custom HTTP requests (e.g., PUT, DELETE, PATCH) with full control over request options including headers, body, proxy, timeout, and redirect behavior.
```APIDOC
## Custom HTTP Request with Options
Executes custom HTTP requests (PUT, DELETE, PATCH, etc.) with full control over request options including proxy, timeout, and redirect behavior.
### Method
`client.Do(url string, options cycletls.Options, method string)`
### Endpoint
`client.Do`
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
- **url** (string) - The URL for the request.
- **options** (*cycletls.Options*) - A struct containing detailed request options:
- **Headers** (map[string]string) - Custom headers.
- **Body** (string) - Request body content.
- **Proxy** (string) - Proxy server URL (e.g., `http://proxy.company.com:8080`).
- **Timeout** (int) - Request timeout in seconds.
- **DisableRedirect** (bool) - Whether to disable automatic redirects.
- **UserAgent** (string) - Custom User-Agent string (defaults to CloudScraper's if empty).
- **Ja3** (string) - Custom JA3 fingerprint string (defaults to CloudScraper's if empty).
- **method** (string) - The HTTP method (e.g., "PUT", "DELETE", "PATCH").
### Request Example
```go
package main
import (
"fmt"
"github.com/Danny-Dasilva/CycleTLS/cycletls"
"github.com/RomainMichau/cloudscraper_go/cloudscraper"
)
func main() {
client, err := cloudscraper.Init(false, false)
if err != nil {
fmt.Printf("Error: %v\n", err)
return
}
options := cycletls.Options{
Headers: map[string]string{
"X-API-Key": "secret-key",
"Content-Type": "application/xml",
},
Body: "Test",
Proxy: "http://proxy.company.com:8080",
Timeout: 10,
DisableRedirect: true,
UserAgent: "", // Will use CloudScraper's default
Ja3: "", // Will use CloudScraper's default
}
// PUT request
response, err := client.Do("https://api.example.com/resource/123", options, "PUT")
if err != nil {
fmt.Printf("Request failed: %v\n", err)
return
}
fmt.Printf("Status: %d\n", response.Status)
fmt.Printf("Body: %s\n", response.Body)
// DELETE request with different options
deleteOptions := cycletls.Options{
Headers: map[string]string{"Authorization": "Bearer token"},
Timeout: 5,
}
deleteResp, err := client.Do("https://api.example.com/resource/123", deleteOptions, "DELETE")
if err != nil {
fmt.Printf("Delete failed: %v\n", err)
return
}
fmt.Printf("Delete Status: %d\n", deleteResp.Status)
}
```
### Response
#### Success Response (200)
- **response.Status** (int) - The HTTP status code of the response.
- **response.Body** (string) - The response body content.
#### Response Example
```json
{
"Status": 200,
"Body": "{\"message\": \"Resource updated\"}"
}
```
```
--------------------------------
### Make POST Request
Source: https://context7.com/romainmichau/cloudscraper_go/llms.txt
Performs an HTTP POST request to the specified URL with custom headers and a request body. This method is useful for submitting data, such as login credentials.
```APIDOC
## Make POST Request
Performs an HTTP POST request with custom headers and request body.
### Method
POST
### Endpoint
`client.Post(url string, headers map[string]string, body string)`
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
- **url** (string) - The URL to send the POST request to.
- **headers** (map[string]string) - A map of custom headers to include in the request.
- **body** (string) - The request body content.
### Request Example
```go
package main
import (
"fmt"
"github.com/RomainMichau/cloudscraper_go/cloudscraper"
)
func main() {
client, err := cloudscraper.Init(false, false)
if err != nil {
fmt.Printf("Error: %v\n", err)
return
}
headers := map[string]string{
"Content-Type": "application/json",
"Authorization": "Bearer abc123",
}
body := `{"username": "user@example.com", "password": "secret"}`
response, err := client.Post("https://api.example.com/login", headers, body)
if err != nil {
fmt.Printf("POST request failed: %v\n", err)
return
}
fmt.Printf("Response Status: %d\n", response.Status)
fmt.Printf("Response Body: %s\n", response.Body)
}
```
### Response
#### Success Response (200)
- **response.Status** (int) - The HTTP status code of the response.
- **response.Body** (string) - The response body content.
#### Response Example
```json
{
"Response Status": 200,
"Response Body": "{\"message\": \"Login successful\"}"
}
```
```
--------------------------------
### Perform Asynchronous HTTP Requests with Cloudscraper Go
Source: https://github.com/romainmichau/cloudscraper_go/blob/master/readMe.md
This snippet illustrates how to perform asynchronous HTTP requests using Cloudscraper Go. It initializes the client for async operations, queues a request with custom options via CycleTLS, and then retrieves the response from a channel. Dependencies include 'cycletls' and 'cloudscraper_go'.
```go
package main
import (
"github.com/Danny-Dasilva/CycleTLS/cycletls"
"github.com/RomainMichau/cloudscraper_go/cloudscraper"
)
func main() {
client, _ := cloudscraper.Init(false, true)
options := cycletls.Options{
Headers: map[string]string{"my_custom_header": "header_value"},
Body: "",
Timeout: 10,
DisableRedirect: true,
}
client.Queue("https://www.facebook.com/anything", options, "PUT")
respChannel := client.RespChan()
res := <-respChannel
print(res.Body)
}
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.