Attribute extractor added. HTML extractor added. Outer HTML Extractor added.
exporter package renamed to export, extractor package renamed to extract for simplicity.
This commit is contained in:
24
extract/attr.go
Normal file
24
extract/attr.go
Normal file
@ -0,0 +1,24 @@
|
||||
package extract
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/PuerkitoBio/goquery"
|
||||
)
|
||||
|
||||
var ErrAttrNotExists = errors.New("attribute not exist")
|
||||
|
||||
// Attr returns HTML attribute value of provided selector
|
||||
type Attr struct {
|
||||
Name string
|
||||
Selector string
|
||||
Attr string
|
||||
}
|
||||
|
||||
// Extract returns HTML attribute value of provided selector
|
||||
func (e *Attr) Extract(doc *goquery.Document) (interface{}, error) {
|
||||
attr, exists := doc.Find(e.Selector).Attr(e.Attr)
|
||||
if !exists {
|
||||
return nil, ErrAttrNotExists
|
||||
}
|
||||
return map[string]string{e.Name: attr}, nil
|
||||
}
|
Reference in New Issue
Block a user