
⚙️ Prerequisites
- Proxy (Optional)
- GO installed
- Capsolver API key
👨💻 GO Code for solve FunCaptcha without proxy
Here's a GO sample script to accomplish the task:
package main
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
"time"
)
const (
clientKey = "" // Replace with your actual CAPSOLVER_KEY
)
func main() {
pageURL := "page"
siteKey := "site key" // Replace with your proxy
taskID, err := solveFunCaptcha(pageURL, siteKey, clientKey)
if err != nil {
fmt.Println("Error:", err)
return
}
if taskID != "" {
solution, err := getTaskResult(taskID, clientKey)
if err != nil {
fmt.Println("Error:", err)
return
}
solutionToken, ok := solution["token"].(string)
if !ok {
fmt.Println("No token found in the solution")
return
}
fmt.Println("Solution token:", solutionToken)
}
}
func solveFunCaptcha(pageURL, websitePublicKey, clientKey string) (string, error) {
payload := map[string]interface{}{
"clientKey": clientKey,
"task": map[string]string{
"type": "FunCaptchaTaskProxyLess",
"websiteURL": pageURL,
"websitePublicKey": websitePublicKey,
},
}
data, err := json.Marshal(payload)
if err != nil {
return "", err
}
fmt.Println("Creating Task")
resp, err := http.Post("https://api.capsolver.com/createTask", "application/json", bytes.NewBuffer(data))
if err != nil {
return "", err
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
return "", fmt.Errorf("Error creating task: Received HTTP status %d", resp.StatusCode)
}
var response map[string]interface{}
err = json.NewDecoder(resp.Body).Decode(&response)
if err != nil {
return "", err
}
taskID, ok := response["taskId"].(string)
fmt.Println("Got Task id " + taskID)
if !ok {
return "", fmt.Errorf("No taskId found in the response")
}
return taskID, nil
}
func getTaskResult(taskID, clientKey string) (map[string]interface{}, error) {
payload := map[string]string{
"clientKey": clientKey,
"taskId": taskID,
}
for {
fmt.Println("Getting Task Result")
data, err := json.Marshal(payload)
if err != nil {
return nil, err
}
resp, err := http.Post("https://api.capsolver.com/getTaskResult", "application/json", bytes.NewBuffer(data))
if err != nil {
return nil, err
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
return nil, fmt.Errorf("Error getting task result: Received HTTP status %d", resp.StatusCode)
}
var result map[string]interface{}
err = json.NewDecoder(resp.Body).Decode(&result)
if err != nil {
return nil, err
}
status, ok := result["status"].(string)
if !ok {
return nil, fmt.Errorf("No status found in the response")
}
if status == "ready" {
return result["solution"].(map[string]interface{}), nil
}
time.Sleep(3 * time.Second)
}
}
👨💻 GO Code for solve FunCaptcha with proxy
Here's a GO sample script to accomplish the task:
package main
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
"time"
)
const (
clientKey = "" // Replace with your actual CAPSOLVER_KEY
)
func main() {
pageURL := "page"
siteKey := "site key" // Replace with your proxy
proxyURL := "http://password:username@host:port"
taskID, err := solveFunCaptcha(pageURL, siteKey, proxy, clientKey)
if err != nil {
fmt.Println("Error:", err)
return
}
if taskID != "" {
solution, err := getTaskResult(taskID, clientKey)
if err != nil {
fmt.Println("Error:", err)
return
}
solutionToken, ok := solution["token"].(string)
if !ok {
fmt.Println("No token found in the solution")
return
}
fmt.Println("Solution token:", solutionToken)
}
}
func solveFunCaptcha(pageURL, websitePublicKey,proxy, clientKey string) (string, error) {
payload := map[string]interface{}{
"clientKey": clientKey,
"task": map[string]string{
"type": "FunCaptchaTask",
"websiteURL": pageURL,
"websitePublicKey": websitePublicKey,
"proxy": proxy,
},
}
data, err := json.Marshal(payload)
if err != nil {
return "", err
}
fmt.Println("Creating Task")
resp, err := http.Post("https://api.capsolver.com/createTask", "application/json", bytes.NewBuffer(data))
if err != nil {
return "", err
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
return "", fmt.Errorf("Error creating task: Received HTTP status %d", resp.StatusCode)
}
var response map[string]interface{}
err = json.NewDecoder(resp.Body).Decode(&response)
if err != nil {
return "", err
}
taskID, ok := response["taskId"].(string)
fmt.Println("Got Task id " + taskID)
if !ok {
return "", fmt.Errorf("No taskId found in the response")
}
return taskID, nil
}
func getTaskResult(taskID, clientKey string) (map[string]interface{}, error) {
payload := map[string]string{
"clientKey": clientKey,
"taskId": taskID,
}
for {
fmt.Println("Getting Task Result")
data, err := json.Marshal(payload)
if err != nil {
return nil, err
}
resp, err := http.Post("https://api.capsolver.com/getTaskResult", "application/json", bytes.NewBuffer(data))
if err != nil {
return nil, err
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
return nil, fmt.Errorf("Error getting task result: Received HTTP status %d", resp.StatusCode)
}
var result map[string]interface{}
err = json.NewDecoder(resp.Body).Decode(&result)
if err != nil {
return nil, err
}
status, ok := result["status"].(string)
if !ok {
return nil, fmt.Errorf("No status found in the response")
}
if status == "ready" {
return result["solution"].(map[string]interface{}), nil
}
time.Sleep(3 * time.Second)
}
}
⚠️ Change these variables
- proxyURL: Change to your proxy, only if you use FunCaptchaTask.
- clientKey: Obtain your API key from the Capsolver Dashboard.
- pageURL: Replace with the URL of the website for which you wish to solve FunCaptcha
- siteKey: Replace with the site key of the page with FunCaptcha