Documentation
¶
Overview ¶
Package web interacts with web pages.
Index ¶
- Variables
- func GetAttr(n *html.Node, attr string) (string, bool)
- func GetText(n *html.Node, addSpaces bool) string
- func Open(ctx context.Context, method, url string, opts ...OpenOption) (*http.Response, error)
- func SetUserAgent(ua string)
- type OpenOption
- type Page
- type QueryAllResult
- type QueryResult
Constants ¶
This section is empty.
Variables ¶
var OpenDisableCompression = func(_ *http.Request, cl *http.Client) { if cl.Transport == nil { cl.Transport = &http.Transport{} } cl.Transport.(*http.Transport).DisableCompression = true }
OpenDisableCompression disables compression so that Content-Length will be usable.
Functions ¶
func GetAttr ¶ added in v0.1.14
GetAttr returns the first occurrence of the named attribute in n. If the attribute is not present, it returns an empty string and false.
func Open ¶ added in v0.1.14
Open returns an HTTP connection to the supplied URL, following redirects. An error and a nil response are returned for non-200 status codes. The caller is responsible for closing the response's Body field.
func SetUserAgent ¶
func SetUserAgent(ua string)
SetUserAgent sets a value for the "User-Agent" header to be sent in all future HTTP requests.
Types ¶
type OpenOption ¶ added in v0.1.14
OpenOption configures Open's behavior.
func OpenSetHeader ¶ added in v0.1.14
func OpenSetHeader(k, v string) OpenOption
OpenSetHeader sets the named header to the supplied value.
type Page ¶
Page represents a parsed HTML page.
func (*Page) Query ¶
func (p *Page) Query(query string) QueryResult
Query calls QueryNode using p.Root.
func (*Page) QueryAll ¶
func (p *Page) QueryAll(query string) QueryAllResult
QueryAll returns all nodes matched by the supplied CSS selector. Unlike Query/QueryNode, an error is not returned if no nodes are matched.
type QueryAllResult ¶
QueryAllResult contains the result of a call to QueryAll.
type QueryResult ¶
QueryResult contains the result of a call to Query or QueryNode.
func QueryNode ¶
func QueryNode(root *html.Node, query string) QueryResult
QueryNode returns the first node matched by the supplied CSS selector. The returned result has a non-nil Err field if no node was matched.