Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrElementNotVisible = errors.New("element not visible")
var ErrEmptyPage = errors.New("page is empty")
var ErrNoCrawlingAction = errors.New("no more actions to crawl")
Functions ¶
This section is empty.
Types ¶
type Crawler ¶
type Crawler struct {
// contains filtered or unexported fields
}
func (*Crawler) GetCrawlGraph ¶
func (c *Crawler) GetCrawlGraph() *graph.CrawlGraph
type Hooks ¶ added in v1.7.0
type Hooks struct {
// BeforeAction is invoked just before each action is dispatched, including
// actions that will subsequently fail. A non-nil error aborts the action.
BeforeAction func(page *browser.BrowserPage, action *types.Action) error
// AfterAction is invoked only after an action completes successfully.
// It is not called when the action returns an error. A non-nil error from
// AfterAction is returned in place of the (otherwise nil) action error.
AfterAction func(page *browser.BrowserPage, action *types.Action) error
// state restoration, immediately before page.NavigateBack(). A non-nil
// error aborts the navigation.
BeforeNavigateBack func(page *browser.BrowserPage) error
}
Hooks bundles optional lifecycle callbacks invoked by the headless crawler. All fields are optional; nil callbacks are skipped.
Callbacks run synchronously on the crawler's own goroutine and block its progress for their duration — they should return quickly. A non-nil error returned from any callback aborts the surrounding crawl step and is propagated back to the caller of Crawl.
A Hooks value is consulted on every action; callers may safely mutate the fields between Crawl invocations but should not mutate them while a Crawl is in flight. If multiple Crawl invocations run concurrently on the same engine the callbacks must themselves be safe to call concurrently.
The supplied *browser.BrowserPage embeds *rod.Page (page.Page) for callers that want to reach the raw rod API. Callbacks should treat the page as read-only — navigating, closing, or otherwise mutating it from inside a callback races with the crawler.
type Options ¶
type Options struct {
Context context.Context
ChromiumPath string
MaxBrowsers int
MaxDepth int
PageMaxTimeout time.Duration
NoSandbox bool
NoIncognito bool
ShowBrowser bool
SlowMotion bool
MaxCrawlDuration time.Duration
MaxFailureCount int
Trace bool
CookieConsentBypass bool
AutomaticFormFill bool
PageLoadStrategy string
ChromeWSUrl string
DOMWaitTime int
UserDataDir string
// EnableDiagnostics enables the diagnostics mode
// which writes diagnostic information to a directory
// specified by the DiagnosticsDir optionally.
EnableDiagnostics bool
DiagnosticsDir string
Proxy string
Logger *slog.Logger
ScopeValidator browser.ScopeValidator
RequestCallback func(*output.Result)
ChromeUser *user.User
CaptchaHandler *captcha.Handler
UserArguments map[string]string
AuthUsername string
AuthPassword string
DitClassifier *dit.Classifier
// Hooks installs optional lifecycle callbacks. See Hooks for semantics.
// The zero value disables all callbacks.
Hooks Hooks
}