Skip to content

Commit

Permalink
[enh] add HTMLElement.ChildAttrs() method - closes #50
Browse files Browse the repository at this point in the history
  • Loading branch information
asciimoo committed Nov 13, 2017
1 parent 741a24d commit ac6587e
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions colly.go
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,18 @@ func (h *HTMLElement) ChildAttr(goquerySelector, attrName string) string {
return ""
}

// ChildAttrs returns the stripped text content of all the matching
// element's attributes.
func (h *HTMLElement) ChildAttrs(goquerySelector, attrName string) []string {
res := make([]string, 0)
h.DOM.Find(goquerySelector).Each(func(_ int, s *goquery.Selection) {
if attr, ok := s.Attr(attrName); ok {
res = append(res, strings.TrimSpace(attr))
}
})
return res
}

// AbsoluteURL returns with the resolved absolute URL of an URL chunk.
// AbsoluteURL returns empty string if the URL chunk is a fragment or
// could not be parsed
Expand Down

0 comments on commit ac6587e

Please sign in to comment.