Extractors refactored to support pass by value. Documentation added for request and response.
This commit is contained in:
@@ -1,14 +1,22 @@
|
||||
package extract
|
||||
|
||||
import "github.com/PuerkitoBio/goquery"
|
||||
import (
|
||||
"github.com/PuerkitoBio/goquery"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Text returns the combined text contents of provided selector.
|
||||
type Text struct {
|
||||
Name string
|
||||
Selector string
|
||||
Name string
|
||||
Selector string
|
||||
TrimSpace bool
|
||||
}
|
||||
|
||||
// Extract returns the combined text contents of provided selector.
|
||||
func (e *Text) Extract(doc *goquery.Document) (interface{}, error) {
|
||||
return map[string]string{e.Name: doc.Find(e.Selector).Text()}, nil
|
||||
func (e Text) Extract(sel *goquery.Selection) (interface{}, error) {
|
||||
text := sel.Find(e.Selector).Text()
|
||||
if e.TrimSpace {
|
||||
text = strings.TrimSpace(text)
|
||||
}
|
||||
return map[string]string{e.Name: text}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user