bread

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2024 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Headers = make(map[string]string)

	Cookies = make(map[string]string)
)

Init a new HTTP client for use when the client doesn't want to use their own.

Functions

func Cookie(n, v string)

Cookie sets a cookie for http requests

func Get

func Get(url string) (string, error)

Get returns the HTML returned by the url as a string using the default HTTP client

func GetWithClient

func GetWithClient(url string, client *http.Client) (string, error)

GetWithClient returns the HTML returned by the url using a provided HTTP client

func Header(n, v string)

Header sets a new HTTP header

func Post

func Post(url string, bodyType string, body interface{}) (string, error)

Post returns the HTML returned by the url as a string using the default HTTP client

func PostForm

func PostForm(url string, data internet.Values) (string, error)

PostForm is a convenience method for POST requests that

func PostWithClient

func PostWithClient(url string, bodyType string, body interface{}, client *http.Client) (string, error)

PostWithClient returns the HTML returned by the url using a provided HTTP client The type of the body must conform to one of the types listed in func getBodyReader()

func SetDebug

func SetDebug(d bool)

SetDebug sets the debug status Setting this to true causes the panics to be thrown and logged onto the console. Setting this to false causes the errors to be saved in the Error field in the returned struct.

Types

type Error

type Error struct {
	Type ErrorType
	// contains filtered or unexported fields
}

Error allows easier introspection on the type of error returned. If you know you have a Error, you can compare the Type to one of the exported types from this package to see what kind of error it is, then further inspect the Error() method to see if it has more specific details for you, like in the case of a ErrElementNotFound type of error.

func (Error) Error

func (se Error) Error() string

type ErrorType

type ErrorType int

ErrorType defines types of errors that are possible from soup

const (
	ErrUnableToParse ErrorType = iota
	ErrElementNotFound
	ErrNoNextSibling
	ErrNoPreviousSibling
	ErrNoNextElementSibling
	ErrNoPreviousElementSibling
	ErrCreatingGetRequest
	ErrInGetRequest
	ErrCreatingPostRequest
	ErrMarshallingPostRequest
	ErrReadingResponse
)

type Root

type Root struct {
	Pointer   *html.Node
	NodeValue string
	Error     error
}

A structure containing a pointer to an html node, the node value, and an error variable to return an error if one occurred

func HTMLParse

func HTMLParse(s string) Root

HTMLParse parses the HTML returning a start pointer to the DOM

func (Root) Attrs

func (r Root) Attrs() map[string]string

Attrs returns a map containing all attributes

func (Root) Children

func (r Root) Children() []Root

Children returns all direct children of this DOME element.

func (Root) Find

func (r Root) Find(args ...string) Root

Find finds the first occurrence of the given tag name, with or without attribute key and value specified, and returns a struct with a pointer to it

func (Root) FindAll

func (r Root) FindAll(args ...string) []Root

FindAll finds all occurrences of the given tag name, with or without key and value specified, and returns an array of structs, each having the respective pointers

func (Root) FindAllStrict

func (r Root) FindAllStrict(args ...string) []Root

FindAllStrict finds all occurrences of the given tag name only if all the values of the provided attribute are an exact match

func (Root) FindNextElementSibling

func (r Root) FindNextElementSibling() Root

FindNextElementSibling finds the next element sibling of the pointer in the DOM returning a struct with a pointer to it

func (Root) FindNextSibling

func (r Root) FindNextSibling() Root

FindNextSibling finds the next sibling of the pointer in the DOM returning a struct with a pointer to it

func (Root) FindPrevElementSibling

func (r Root) FindPrevElementSibling() Root

FindPrevElementSibling finds the previous element sibling of the pointer in the DOM returning a struct with a pointer to it

func (Root) FindPrevSibling

func (r Root) FindPrevSibling() Root

FindPrevSibling finds the previous sibling of the pointer in the DOM returning a struct with a pointer to it

func (Root) FindStrict

func (r Root) FindStrict(args ...string) Root

FindStrict finds the first occurrence of the given tag name only if all the values of the provided attribute are an exact match

func (Root) FullText

func (r Root) FullText() string

FullText returns the string inside even a nested element

func (Root) HTML

func (r Root) HTML() string

HTML returns the HTML code for the specific element

func (Root) Text

func (r Root) Text() string

Text returns the string inside a non-nested element

Jump to

Keyboard shortcuts

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