Documentation ¶
Index ¶
Constants ¶
View Source
const ( TagA = "a" TagLink = "link" TagImg = "img" TagScript = "script" )
HTML tags we care about
View Source
const ( AttrHref = "href" AttrSrc = "src" )
Attribute types we look for,
Variables ¶
View Source
var ByToken = Func(func(body []byte) (Results, error) { tokenizer := html.NewTokenizer(bytes.NewReader(body)) results := Results{} for { tokenType := tokenizer.Next() switch tokenType { case html.ErrorToken: err := tokenizer.Err() if err == io.EOF { return results, nil } return results, err case html.StartTagToken: token := tokenizer.Token() if isTag(token, TagA) { href := filterAttrByName(token, AttrHref) if href == nil { continue } uri, err := url.Parse(*href) if err != nil { continue } results.Links = append(results.Links, uri) continue } if isTag(token, TagImg) || isTag(token, TagScript) { src := filterAttrByName(token, AttrSrc) if src == nil { continue } results.Assets = append(results.Assets, *src) } if isTag(token, TagLink) { href := filterAttrByName(token, AttrHref) if href == nil { continue } results.Assets = append(results.Assets, *href) continue } } } })
ByToken iterates over tokens in the response, pulling out links and assets.
Functions ¶
This section is empty.
Types ¶
Click to show internal directories.
Click to hide internal directories.