SiteNavigator

package
v0.2.35 Latest Latest
Warning

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

Go to latest
Published: May 5, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractContentFromDocument

func ExtractContentFromDocument(doc *html.Node, criteria *SearchCriteria) (*html.Node, error)

ExtractContentFromDocument performs a depth-first search on an HTML document, finding the first node that matches the provided search criteria.

Parameters:

  • doc: The HTML document to search within.
  • criteria: The search criteria to apply to each node.

Returns:

  • *html.Node: The first node that matches the search criteria, nil if no matching node is found.

func ExtractNodes

func ExtractNodes(section *html.Node, criterias []SearchCriteria) []html.Node

ExtractNodes performs a breadth-first search on an HTML section returning a slice of nodes that match the provided search criteria.

Parameters:

  • section: The HTML section to search within.
  • criterias: A list of search criteria to apply to each node.

Returns:

  • []*html.Node: A slice containing all nodes that match the search criteria.

Behavior:

  • If no criteria is provided, then any node will match.

func ExtractSpecificNode

func ExtractSpecificNode(node *html.Node, criteria *SearchCriteria) []html.Node

ExtractSpecificNode finds all nodes that match the given search criteria and that are direct children of the provided node.

Parameters:

  • node: The HTML node to search within.
  • criteria: The search criteria to apply to each node.

Returns:

  • nodes: A slice containing all nodes that match the search criteria.

Behavior:

  • If no criteria is provided, then any node will match.
  • If the node is nil, then a nil slice is returned.

func GetDirectChildren added in v0.2.14

func GetDirectChildren(node *html.Node) []html.Node

GetDirectChildren returns a slice of the direct children of the provided node.

Parameters:

  • node: The HTML node to extract the children from.

Returns:

  • []*html.Node: A slice containing the direct children of the node.

func MatchNodes added in v0.2.13

func MatchNodes(section *html.Node, criteria *SearchCriteria) ([]html.Node, error)

MatchNodes performs a breadth-first search on an HTML section returning a slice of nodes that match the provided search criteria.

Parameters:

  • section: The HTML section to search within.
  • criteria: The search criteria to apply to each node.

Returns:

  • []*html.Node: A slice containing all nodes that match the search criteria.

Behavior:

  • It does not search the children of the nodes that match the criteria.
  • If no criteria is provided, then the first node will match.

Types

type AttributeMatchFunc added in v0.2.34

type AttributeMatchFunc func(attr string) bool

AttributeMatchFunc is a function type that takes a string and returns a boolean. It is used to match an attribute value in an HTML node.

Parameters:

  • attr: The attribute value to match.

Returns:

  • bool: True if the attribute value matches, otherwise false.

type SearchCriteria

type SearchCriteria struct {
	// NodeType specifies the type of the HTML node to search for.
	NodeType html.NodeType

	// Data represents the data contained within the node.
	Data optional.String

	// AttrKey is a slice of attribute keys to match.
	AttrKey []string

	// AttrVal is a slice of functions that match the attribute value.
	AttrVal []AttributeMatchFunc
}

SearchCriteria is a struct that encapsulates the parameters for searching within an HTML node.

var IsTextNodeSearch SearchCriteria = NewSearchCriteria(html.TextNode)

IsTextNodeSearch is a search criteria that matches text nodes.

func NewSearchCriteria

func NewSearchCriteria(node_type html.NodeType, options ...SearchCriteriaOption) SearchCriteria

NewSearchCriteria constructs a new SearchCriteria instance using the provided parameters.

Parameters:

  • node_type: The type of the HTML node to search for.
  • options: A variadic list of functional options to apply to the SearchCriteria instance.

Returns:

  • SearchCriteria: SearchCriteria instance with the specified parameters.

func (*SearchCriteria) Match

func (sc *SearchCriteria) Match(node *html.Node) bool

Match is a method of the SearchCriteria type that evaluates whether a given HTML node matches the search criteria encapsulated by the SearchCriteria instance.

Parameters:

  • node: The HTML node to match against the search criteria.

Returns:

  • bool: True if the node matches the search criteria, otherwise false.

type SearchCriteriaOption

type SearchCriteriaOption func(*SearchCriteria)

SearchCriteriaOption is a functional option type for the SearchCriteria struct.

Parameters:

  • *SearchCriteria: The SearchCriteria instance to apply the option to.

func WithAttr

WithAttr is a functional option that sets the attribute key-value pair to match in the SearchCriteria instance.

Parameters:

  • key: The attribute key to match.
  • val: The attribute value to match.

Returns:

  • SearchCriteriaOption: A functional option that sets the attribute key-value pair to match in the SearchCriteria instance.

func WithData

func WithData(data string) SearchCriteriaOption

WithData is a functional option that sets the data field of the SearchCriteria instance to the provided string.

Parameters:

  • data: The data to set in the SearchCriteria instance.

Returns:

  • SearchCriteriaOption: A functional option that sets the data field of the

Jump to

Keyboard shortcuts

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