Documentation ¶
Index ¶
- func ExtractContentFromDocument(doc *html.Node, criteria *SearchCriteria) *html.Node
- func ExtractNodes(section *html.Node, searchCriteria []*SearchCriteria) []*html.Node
- func ExtractSpecificNode(node *html.Node, criteria *SearchCriteria) (nodes []*html.Node)
- type SearchCriteria
- type SearchCriteriaOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExtractContentFromDocument ¶
func ExtractContentFromDocument(doc *html.Node, criteria *SearchCriteria) *html.Node
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, searchCriteria []*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.
- searchCriteria: A list of search criteria to apply to each node.
Returns:
- []*html.Node: A slice containing all nodes that match the search criteria.
func ExtractSpecificNode ¶
func ExtractSpecificNode(node *html.Node, criteria *SearchCriteria) (nodes []*html.Node)
ExtractSpecificNode finds all nodes that match the given search criteria and that are direct children of the provided node.
Panics with an error of type *ers.InvalidParameterError if the node is nil.
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.
If no criteria is provided, then any node will match.
Types ¶
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 and AttrVal define the attribute key-value pair to match in the // node. AttrKey []string AttrVal []func(string) bool }
SearchCriteria is a struct that encapsulates the parameters for searching within an HTML node.
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: The newly created SearchCriteria instance.
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 ¶
func WithAttr(key string, val func(string) bool) SearchCriteriaOption
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