Files
go-flaresolverr/test/flaresolverr_test.go

64 lines
1.4 KiB
Go

package test
import (
"encoding/json"
"fmt"
"testing"
"git.nite07.com/nite/go-flaresolverr"
"github.com/Danny-Dasilva/CycleTLS/cycletls"
)
func TestGetV1(t *testing.T) {
f, err := flaresolverr.GetInstance("http://100.64.0.1:8191", "", "")
if err != nil {
t.Error(err)
return
}
resp, err := f.GetV1("https://nopecha.com/demo/cloudflare", nil)
if err != nil {
t.Error(err)
return
}
if resp.Solution.Status != 200 {
t.Fail()
} else {
jsonBytes, _ := json.Marshal(resp)
t.Log(string(jsonBytes))
}
}
func TestImitateGet(t *testing.T) {
f, err := flaresolverr.GetInstance("http://100.64.0.1:8191", "", "")
if err != nil {
t.Error(err)
return
}
resp, err := f.GetV1("https://nopecha.com/demo/cloudflare", nil) // get cf-clearance cookie
if err != nil {
t.Error(err)
return
}
if resp.Solution.Status != 200 {
t.FailNow()
}
cookies := resp.Solution.Cookies
resp1, err := f.SimulateGet("https://nopecha.com/demo/cloudflare", &flaresolverr.SimulateOptions{
HttpCookies: cookies,
Options: cycletls.Options{
ForceHTTP3: true,
},
}) // ImitateGet uses cookies to simulate browser requests and also simulates the browser's ja3 fingerprint.
if err != nil {
t.Error(err)
return
}
if resp1.Status != 200 {
fmt.Printf("status is not 200: %v", resp1.Status)
fmt.Printf("%+v", resp1)
t.FailNow()
}
jsonBytes, _ := json.Marshal(resp1)
t.Log(string(jsonBytes))
}