browser

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultBrowsers = []string{"chrome", "firefox", "curl"}

DefaultBrowsers defines the priority order for browsers

Functions

func CleanHTML

func CleanHTML(content []byte, opts *CleaningOptions) []byte

CleanHTML removes unwanted elements from HTML content based on options

func StripJavaScript

func StripJavaScript(content []byte) []byte

StripJavaScript removes JavaScript code from HTML content

Types

type Browser

type Browser interface {
	// Name returns the name of the browser
	Name() string
	// Fetch retrieves content from a URL
	Fetch(url string) ([]byte, error)
	// SetCleaningOptions sets the HTML cleaning options
	SetCleaningOptions(*CleaningOptions)
}

Browser represents a web browser interface for fetching content

func GetDefaultBrowser

func GetDefaultBrowser() (Browser, error)

GetDefaultBrowser tries browsers in order of preference and returns the first available one

func NewBrowser

func NewBrowser(name string) (Browser, error)

NewBrowser creates a new browser instance based on the browser name

type Chrome

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

func NewChrome

func NewChrome() (*Chrome, error)

func (*Chrome) Fetch

func (c *Chrome) Fetch(url string) ([]byte, error)

func (*Chrome) Name

func (c *Chrome) Name() string

func (*Chrome) SetCleaningOptions

func (c *Chrome) SetCleaningOptions(opts *CleaningOptions)

type CleaningOptions

type CleaningOptions struct {
	KeepHeader   bool // Keep header elements if true
	KeepFooter   bool // Keep footer elements if true
	KeepNav      bool // Keep navigation elements if true
	KeepStyles   bool // Keep inline and internal styles if true
	KeepComments bool // Keep HTML comments if true
}

CleaningOptions configures what elements to remove from HTML

func DefaultCleaningOptions

func DefaultCleaningOptions() *CleaningOptions

DefaultCleaningOptions returns the default cleaning configuration

type Curl

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

func NewCurl

func NewCurl() (*Curl, error)

func (*Curl) Fetch

func (c *Curl) Fetch(url string) ([]byte, error)

func (*Curl) Name

func (c *Curl) Name() string

func (*Curl) SetCleaningOptions

func (c *Curl) SetCleaningOptions(opts *CleaningOptions)

type DefaultExecutableFinder

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

DefaultExecutableFinder implements ExecutableFinder

func (*DefaultExecutableFinder) Find

func (f *DefaultExecutableFinder) Find() (string, error)

type ExecutableFinder

type ExecutableFinder interface {
	Find() (string, error)
}

ExecutableFinder is an interface for finding browser executables

type Firefox

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

func NewFirefox

func NewFirefox() (*Firefox, error)

func (*Firefox) Fetch

func (f *Firefox) Fetch(url string) ([]byte, error)

func (*Firefox) Name

func (f *Firefox) Name() string

func (*Firefox) SetCleaningOptions

func (f *Firefox) SetCleaningOptions(opts *CleaningOptions)
type Links struct {
	// contains filtered or unexported fields
}

Links browser implementation

func NewLinks() (*Links, error)

func (*Links) Fetch

func (l *Links) Fetch(url string) ([]byte, error)

func (*Links) Name

func (l *Links) Name() string

type Lynx

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

Lynx browser implementation

func NewLynx

func NewLynx() (*Lynx, error)

func (*Lynx) Fetch

func (l *Lynx) Fetch(url string) ([]byte, error)

func (*Lynx) Name

func (l *Lynx) Name() string

type W3m

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

W3m browser implementation

func NewW3m

func NewW3m() (*W3m, error)

func (*W3m) Fetch

func (w *W3m) Fetch(url string) ([]byte, error)

func (*W3m) Name

func (w *W3m) Name() string

Jump to

Keyboard shortcuts

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