pup

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2019 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var VERSION string = "0.4.0"

Functions

func GetJSONByte

func GetJSONByte(nodes []*html.Node) []byte

func ParseArgs

func ParseArgs() ([]string, error)

func ParseAttrMatcher

func ParseAttrMatcher(selector *CSSSelector, s scanner.Scanner) error

Parse an attribute matcher e.g. `[attr^="http"]`

func ParseClassMatcher

func ParseClassMatcher(selector *CSSSelector, s scanner.Scanner) error

Parse a class matcher e.g. `.btn`

func ParseCommands

func ParseCommands(cmdString string) ([]string, error)

Split a string with awareness for quoted text and commas

func ParseDisplayer

func ParseDisplayer(cmd string) error

func ParseHTML

func ParseHTML(r io.Reader, cs string) (*html.Node, error)

Parse the html while handling the charset

func ParseIdMatcher

func ParseIdMatcher(selector *CSSSelector, s scanner.Scanner) error

Parse an id matcher e.g. `#my-picture`

func ParsePseudo

func ParsePseudo(selector *CSSSelector, s scanner.Scanner) error

Parse the selector after ':'

func ParseTagMatcher

func ParseTagMatcher(selector *CSSSelector, s scanner.Scanner) error

Parse the initial tag e.g. `div`

func PrintHelp

func PrintHelp(w io.Writer, exitCode int)

func ProcessFlags

func ProcessFlags(cmds []string) (nonFlagCmds []string, err error)

Process command arguments and return all non-flags.

func Run

func Run(_pupIn io.ReadCloser) []byte

Types

type AttrDisplayer

type AttrDisplayer struct {
	Attr string
}

Print the attribute of a node

func (AttrDisplayer) Display

func (a AttrDisplayer) Display(nodes []*html.Node)

type CSSSelector

type CSSSelector struct {
	Tag    string
	Attrs  map[string]*regexp.Regexp
	Pseudo PseudoClass
}

func ParseSelector

func ParseSelector(cmd string) (selector CSSSelector, err error)

Parse a selector e.g. `div#my-button.btn[href^="http"]`

func (CSSSelector) Match

func (s CSSSelector) Match(node *html.Node) bool

type Displayer

type Displayer interface {
	Display([]*html.Node)
}

type JSONDisplayer

type JSONDisplayer struct{}

Print nodes as a JSON list

func (JSONDisplayer) Display

func (j JSONDisplayer) Display(nodes []*html.Node)

type NumDisplayer

type NumDisplayer struct{}

Print the number of features returned

func (NumDisplayer) Display

func (d NumDisplayer) Display(nodes []*html.Node)

type PseudoClass

type PseudoClass func(*html.Node) bool

type Selector

type Selector interface {
	Match(node *html.Node) bool
}

type SelectorFunc

type SelectorFunc func(nodes []*html.Node) []*html.Node

func Select

func Select(s Selector) SelectorFunc

func SelectFromChildren

func SelectFromChildren(s Selector) SelectorFunc

Defined for the '+' selector

func SelectNextSibling

func SelectNextSibling(s Selector) SelectorFunc

Defined for the '>' selector

type TextDisplayer

type TextDisplayer struct{}

Print the text of a node

func (TextDisplayer) Display

func (t TextDisplayer) Display(nodes []*html.Node)

type TreeDisplayer

type TreeDisplayer struct {
}

func (TreeDisplayer) Display

func (t TreeDisplayer) Display(nodes []*html.Node)

Jump to

Keyboard shortcuts

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