// attributeOrDefault reads an attribute and returns it or the default value when it's empty. func (bow *Browser) attrOrDefault(name, def string, sel *goquery.Selection) string { a, ok := sel.Attr(name) if ok { return a } return def }
// attributeToUrl reads an attribute from an element and returns a url. func (bow *Browser) attrToResolvedUrl(name string, sel *goquery.Selection) (*url.URL, error) { src, ok := sel.Attr(name) if !ok { return nil, errors.NewAttributeNotFound( "Attribute '%s' not found.", name) } ur, err := url.Parse(src) if err != nil { return nil, err } return bow.ResolveUrl(ur), nil }
func formAttributes(bow Browsable, s *goquery.Selection) (string, string) { method, ok := s.Attr("method") if !ok { method = "GET" } action, ok := s.Attr("action") if !ok { action = bow.Url().String() } aurl, err := url.Parse(action) if err != nil { return "", "" } aurl = bow.ResolveUrl(aurl) return strings.ToUpper(method), aurl.String() }