add README.md
This commit is contained in:
parent
0f5f67e691
commit
0b35c2ca09
55
README.md
Normal file
55
README.md
Normal file
@ -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))
|
||||
}
|
||||
```
|
56
test/flaresolverr_test.go
Normal file
56
test/flaresolverr_test.go
Normal file
@ -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))
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user