diff --git a/README.md b/README.md new file mode 100644 index 0000000..2e0d44c --- /dev/null +++ b/README.md @@ -0,0 +1,55 @@ +# go-flaresolverr + +A Go package that simplifies FlareSolverr API calls. + +## Usage + +```go +func TestGetV1(t *testing.T) { + f, err := flaresolverr.GetInstance("http://127.0.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://127.0.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, + }) // 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 { + t.FailNow() + } + jsonBytes, _ := json.Marshal(resp1) + t.Log(string(jsonBytes)) +} +``` diff --git a/test/flaresolverr_test.go b/test/flaresolverr_test.go new file mode 100644 index 0000000..13645e5 --- /dev/null +++ b/test/flaresolverr_test.go @@ -0,0 +1,56 @@ +package test + +import ( + "encoding/json" + "testing" + + "git.nite07.com/nite/flaresolverr" +) + +func TestGetV1(t *testing.T) { + f, err := flaresolverr.GetInstance("http://127.0.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://127.0.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, + }) // 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 { + t.FailNow() + } + jsonBytes, _ := json.Marshal(resp1) + t.Log(string(jsonBytes)) +}