Documentation
¶
Index ¶
- Constants
- Variables
- func ConvertHeaderToMap(header http.Header) map[string]interface{}
- func ConvertMapToHeader(m map[string]interface{}) http.Header
- func NewRedirectionHandler(maxRedirect int) func(req *http.Request, via []*http.Request) error
- func SetDefaultHeader(header http.Header, key string, value string) http.Header
- type Client
- func (c *Client) Cookies(URL string) []*http.Cookie
- func (c *Client) DoRequest(req *Request) (resp *Response, err error)
- func (c *Client) DoRequestChrome(req *Request) (*Response, error)
- func (c *Client) DoRequestClient(req *Request) (*Response, error)
- func (c *Client) SetCookies(URL string, cookies []*http.Cookie) error
- type Request
- type Response
Constants ¶
const ( DefaultUserAgent = "Geziyor 1.0" DefaultMaxBody int64 = 1024 * 1024 * 1024 // 1GB DefaultRetryTimes = 2 )
Variables ¶
var ( // ErrNoCookieJar is the error type for missing cookie jar ErrNoCookieJar = errors.New("cookie jar is not available") ErrWrongStatus = errors.New("wrong response status code") )
var (
DefaultRetryHTTPCodes = []int{500, 502, 503, 504, 522, 524, 408}
)
Functions ¶
func ConvertHeaderToMap ¶
ConvertHeaderToMap converts http.Header to map[string]interface{}
func ConvertMapToHeader ¶
ConvertMapToHeader converts map[string]interface{} to http.Header
func NewRedirectionHandler ¶
NewRedirectionHandler returns maximum allowed redirection function with provided maxRedirect
Types ¶
type Client ¶
Client is a small wrapper around *http.Client to provide new methods.
func NewClient ¶
func NewClient(maxBodySize int64, charsetDetectDisabled bool, retryTimes int, retryHTTPCodes []int) *Client
NewClient creates http.Client with modified values for typical web scraper
func (*Client) DoRequestChrome ¶
DoRequestChrome opens up a new chrome instance and makes request
func (*Client) DoRequestClient ¶
DoRequestClient is a simple wrapper to read response according to options.
type Request ¶
type Request struct {
*http.Request
// Meta contains arbitrary data.
// Use this Meta map to store contextual data between your requests
Meta map[string]interface{}
// If true, requests will be synchronized
Synchronized bool
// If true request will be opened in Chrome and
// fully rendered HTML DOM response will returned as response
Rendered bool
// Optional response body encoding. Leave empty for automatic detection.
// If you're having issues with auto detection, set this.
Encoding string
// Set this true to cancel requests. Should be used on middlewares.
Cancelled bool
// contains filtered or unexported fields
}
Request is a small wrapper around *http.Request that contains Metadata and Rendering option
func NewRequest ¶
NewRequest returns a new Request given a method, URL, and optional body.
type Response ¶
type Response struct {
*http.Response
// Response body
Body []byte
// Goquery Document object. If response IsHTML, its non-nil.
HTMLDoc *goquery.Document
Request *Request
}
Response type wraps http.Response Contains parsed response data and Geziyor functions.