Skip to content

Commit

Permalink
Merge pull request gocolly#391 from pfaaj/master
Browse files Browse the repository at this point in the history
added ChildTexts method to htmlelement
  • Loading branch information
asciimoo authored Nov 15, 2019
2 parents a20f330 + 18c33ec commit eeee2d6
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions htmlelement.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,17 @@ func (h *HTMLElement) ChildText(goquerySelector string) string {
return strings.TrimSpace(h.DOM.Find(goquerySelector).Text())
}

// ChildTexts returns the stripped text content of all the matching
// elements.
func (h *HTMLElement) ChildTexts(goquerySelector string) []string {
var res []string
h.DOM.Find(goquerySelector).Each(func(_ int, s *goquery.Selection) {

res = append(res, strings.TrimSpace(s.Text()))
})
return res
}

// ChildAttr returns the stripped text content of the first matching
// element's attribute.
func (h *HTMLElement) ChildAttr(goquerySelector, attrName string) string {
Expand Down

0 comments on commit eeee2d6

Please sign in to comment.