flaresolverr

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 26, 2023 License: MIT Imports: 7 Imported by: 0

README

FlareSolverr v3 Go Client

Code Climate Test Coverage GitHub issues CircleCI FOSSA Status

go-flaresolverr is Golang client for FlareSolverr v3.

Installation

  1. Install FlareSolverr
  2. Get go-flaresolverr
go get github.com/astrocode-id/go-flaresolverr

Examples

Get Page

Retrieves webpage using request.get command.

package main

import (
	"fmt"
	"log"

	"github.com/PuerkitoBio/goquery"

	"github.com/astrocode-id/go-flaresolverr"
)

func main() {
	c, err := flaresolverr.NewClient(flaresolverr.Config{
		BaseURL: baseURL,
	})
	if err != nil {
		log.Fatal(err)
	}

	b, err := c.Get(flaresolverr.GetParams{
		URL: "https://ifconfig.me",
	})
	if err != nil {
		log.Fatal(err)
	}

	doc, err := goquery.NewDocumentFromReader(bytes.NewReader(b))
	if err != nil {
		log.Fatal(err)
	}

	ipAddress := doc.Find("strong").First().Text()
	fmt.Println(ipAddress)
}
Post Page

Retrieves webpage using request.post command.

TODO

Note

License

FOSSA Status

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is a simple wrapper around the general Flaresolverr and represents a client to talk with Flaresolverr API.

func NewClient

func NewClient(c Config) (*Client, error)

NewClient is the constructor for Flaresolverr API Client.

func (*Client) Get

func (c *Client) Get(p GetParams) ([]byte, error)

Get requests web page with method http.Get and returns Solution.Response as raw bytes. For more detail, refer to https://github.com/FlareSolverr/FlareSolverr#-requestget.

func (*Client) GetRaw

func (c *Client) GetRaw(p GetParams) (Response, error)

GetRaw requests web page with method http.Get and returns whole Response. For more detail, refer to https://github.com/FlareSolverr/FlareSolverr#-requestget.

func (*Client) Post

func (c *Client) Post(p PostParams) ([]byte, error)

Post requests web page with method http.Post and returns Solution.Response as raw bytes. For more detail, refer to https://github.com/FlareSolverr/FlareSolverr#-requestpost.

func (*Client) PostRaw

func (c *Client) PostRaw(p PostParams) (Response, error)

PostRaw requests web page with method http.Post and returns whole Response. For more detail, refer to https://github.com/FlareSolverr/FlareSolverr#-requestpost.

type Config

type Config struct {
	// BaseURL is for Flaresolverr URL. Default: http://localhost:8191/v1.
	BaseURL string
	// Global Timeout to solve the challenge in milliseconds. Default: No timeout.
	Timeout int
}

Config holds parameters for calling Flaresolverr NewClient.

type Cookies

type Cookies []http.Cookie

Cookies is a helper to manage cookie from Flaresolverr API.

func (Cookies) MarshalJSON

func (c Cookies) MarshalJSON() ([]byte, error)

MarshalJSON is a custom function for marshalling Cookies.

func (*Cookies) UnmarshalJSON

func (c *Cookies) UnmarshalJSON(b []byte) error

UnmarshalJSON is a custom function for UnmarshalJSON Cookies.

type GetParams

type GetParams struct {
	URL string
	// MaxTimeout to solve the challenge in milliseconds for current API
	// It replaces global timeout from Config.Timeout. Default: No timeout.
	MaxTimeout        int
	Cookies           Cookies
	ReturnOnlyCookies bool
}

GetParams holds parameters for calling Get.

type PostParams

type PostParams struct {
	URL               string
	PostData          url.Values
	MaxTimeout        int
	Cookies           Cookies
	ReturnOnlyCookies bool
}

PostParams holds parameters for calling Post.

type Response

type Response struct {
	Status         status   `json:"status,omitempty"`
	Message        string   `json:"message,omitempty"`
	Solution       Solution `json:"solution"`
	StartTimestamp int64    `json:"startTimestamp"`
	EndTimestamp   int64    `json:"endTimestamp"`
	Version        string   `json:"version"`
}

Response holds raw response from Flaresolverr API.

type Solution

type Solution struct {
	URL       string          `json:"url"`
	Status    int             `json:"status"`
	Cookies   Cookies         `json:"cookies"`
	UserAgent string          `json:"userAgent"`
	Response  json.RawMessage `json:"response"`
}

Solution holds scraped web page from Flaresolverr API.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL