hawkgo

package module
v0.0.0-...-d88f9f5 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2021 License: MIT Imports: 16 Imported by: 0

README

hawk-go

Port of HawkAPI's cloudscraper

Everything is exposed to give access to modification, this is subject to change.

Installation: go get github.com/juiced-aio/hawk-go

Example:

import (
    "github.com/useflyent/fhttp/cookiejar"
    hawk "github.com/juiced-aio/hawk-go"
    http "https://github.com/useflyent/fhttp"
)

// Client has to be from fhttp and up to CloudFlare's standards, this can include ja3 fingerprint/http2 settings.

// Client also will need a cookie jar.
cookieJar, _: = cookiejar.New(nil)
client.Jar = cookieJar
scraper: = hawk.Init(client, "YOUR_KEY_HERE", true)

// You will have to create your own function if you want to solve captchas.
scraper.CaptchaFunction = func(originalURL string, siteKey string) (string, error) {
  // CaptchaFunction should return the token as a string.
  return "", nil
}

req, _: = http.NewRequest("GET", "https://www.nakedcph.com/en/product/9468/nike-sportswear-dunk-low-disrupt-ck6654-001", nil)

req.Header = http.Header{
  "sec-ch-ua":                 {`"Chromium";v="92", " Not A;Brand";v="99", "Google Chrome";v="92"`},
  "sec-ch-ua-mobile":          {`?0`},
  "upgrade-insecure-requests": {`1`},
  "user-agent":                {`Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36`},
  "accept":                    {`text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9`},
  "sec-fetch-site":            {`none`},
  "sec-fetch-mode":            {`navigate`},
  "sec-fetch-user":            {`?1`},
  "sec-fetch-dest":            {`document`},
  "accept-encoding":           {`gzip, deflate`},
  "accept-language":           {`en-US,en;q=0.9`},
  http.HeaderOrderKey:         {"sec-ch-ua", "sec-ch-ua-mobile", "upgrade-insecure-requests", "user-agent", "accept", "sec-fetch-site", "sec-fetch-mode", "sec-fetch-user", "sec-fetch-dest", "accept-encoding", "accept-language"},
  http.PHeaderOrderKey:        {":method", ":authority", ":scheme", ":path"},
}

resp, err := scraper.Do(req)

All of the logic is based off of HawkAPIs cloudscraper.

Thanks to zMrKrabz for fhttp

For most questions I'd make a ticket in HawkAPI's discord server but if needed my discord is Humphreyyyy#0088.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckForCaptcha

func CheckForCaptcha(body string) bool

func CreateParams

func CreateParams(paramsLong map[string]string) string

func IsFingerprintChallenge

func IsFingerprintChallenge(response *http.Response) bool

func IsNewCaptchaChallenge

func IsNewCaptchaChallenge(response *http.Response) bool

func IsNewIUAMChallenge

func IsNewIUAMChallenge(response *http.Response) bool

func MirageLog

func MirageLog(message, taskID, module string)

Log prints a status to console.

func MirageSuccess

func MirageSuccess(message, taskID, module string)

Success prints a status to the console.

func ReadAndCopyBody

func ReadAndCopyBody(response *http.Response) ([]byte, error)

func ReadAndUnmarshalBody

func ReadAndUnmarshalBody(respBody io.ReadCloser, x interface{}) error

Types

type Scraper

type Scraper struct {
	Client               http.Client
	CaptchaFunction      func(originalURL string, siteKey string) (string, error)
	FingerprintChallenge bool
	Script               string
	InitScript           *http.Response
	ChallengePayload     *http.Response
	MainPayloadResponse  *http.Response
	InitURL              string
	RequestURL           string
	CaptchaScript        string
	ApiDomain            string
	TimeOut              int
	ErrorDelay           int
	InitHeaders          http.Header
	ChallengeHeaders     http.Header
	SubmitHeaders        http.Header
	OriginalRequest      *http.Response
	Domain               string
	Debug                bool
	Key                  string

	AuthParams                     map[string]string
	Md                             string
	Captcha                        bool
	StartTime                      time.Time
	SolveRetries                   int
	SolveMaxRetries                int
	Result                         string
	Name                           string
	BaseObj                        string
	RequestPass                    string
	RequestR                       string
	TS                             int
	TargetURL                      string
	InitPayloadRetries             int
	InitPayloadMaxRetries          int
	KeyStrUriSafe                  string
	InitChallengeRetries           int
	InitChallengeMaxRetries        int
	FetchingChallengeRetries       int
	FetchingChallengeMaxRetries    int
	SubmitChallengeRetries         int
	SubmitChallengeMaxRetries      int
	ChallengeResultRetries         int
	ChallengeResultMaxRetries      int
	FinalApi                       apiResponse
	SubmitFinalChallengeRetries    int
	SubmitFinalChallengeMaxRetries int
	RerunRetries                   int
	RerunMaxRetries                int
	CaptchaRetries                 int
	CaptchaMaxRetries              int
	FirstCaptchaResult             apiResponse
	CaptchaResponseAPI             apiResponse
	SubmitCaptchaRetries           int
	SubmitCaptchaMaxRetries        int
	// contains filtered or unexported fields
}

func Init

func Init(client http.Client, key string, debug bool, taskID, module string) (scraper Scraper)

func (*Scraper) ChallengeInitiationPayload

func (scraper *Scraper) ChallengeInitiationPayload() (*http.Response, error)

func (*Scraper) Do

func (scraper *Scraper) Do(request *http.Request) (*http.Response, error)

func (*Scraper) Get

func (scraper *Scraper) Get(url string) (resp *http.Response, err error)

func (*Scraper) GetChallengeResult

func (scraper *Scraper) GetChallengeResult() (*http.Response, error)

func (*Scraper) GetPage

func (scraper *Scraper) GetPage() (*http.Response, error)

func (*Scraper) GetPayloadFromAPI

func (scraper *Scraper) GetPayloadFromAPI() (*http.Response, error)

func (*Scraper) HandleCaptcha

func (scraper *Scraper) HandleCaptcha() (*http.Response, error)

In Progress

func (*Scraper) HandleFinalApi

func (scraper *Scraper) HandleFinalApi() (*http.Response, error)

func (*Scraper) HandleLoopError

func (scraper *Scraper) HandleLoopError(errFormat string, err error)

func (*Scraper) HandleRerun

func (scraper *Scraper) HandleRerun() (*http.Response, error)

func (*Scraper) InitiateCloudflare

func (scraper *Scraper) InitiateCloudflare() (*http.Response, error)

func (*Scraper) InitiateScript

func (scraper *Scraper) InitiateScript() (*http.Response, error)

func (*Scraper) Injection

func (scraper *Scraper) Injection(response *http.Response, err error) (*http.Response, error)

func (*Scraper) Post

func (scraper *Scraper) Post(url string, contentType string, body io.Reader) (resp *http.Response, err error)

func (*Scraper) SendMainPayload

func (scraper *Scraper) SendMainPayload() (*http.Response, error)

func (*Scraper) Solve

func (scraper *Scraper) Solve() (*http.Response, error)

func (*Scraper) SolvePayload

func (scraper *Scraper) SolvePayload() (*http.Response, error)

func (*Scraper) SubmitCaptcha

func (scraper *Scraper) SubmitCaptcha() (*http.Response, error)

func (*Scraper) SubmitChallenge

func (scraper *Scraper) SubmitChallenge() (*http.Response, error)

func (*Scraper) SubmitFingerprintChallenge

func (scraper *Scraper) SubmitFingerprintChallenge() (*http.Response, error)

Jump to

Keyboard shortcuts

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