Exporters made optional, as some scrapers only want to see data in console.
This commit is contained in:
19
geziyor.go
19
geziyor.go
@ -4,7 +4,6 @@ import (
|
||||
"bytes"
|
||||
"github.com/PuerkitoBio/goquery"
|
||||
"github.com/fpfeng/httpcache"
|
||||
"github.com/geziyor/geziyor/exporter"
|
||||
"golang.org/x/net/html/charset"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
@ -18,6 +17,11 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// Exporter interface is for extracting data to external resources
|
||||
type Exporter interface {
|
||||
Export(exports *Response)
|
||||
}
|
||||
|
||||
// Geziyor is our main scraper type
|
||||
type Geziyor struct {
|
||||
client *http.Client
|
||||
@ -68,9 +72,6 @@ func NewGeziyor(opt Options) *Geziyor {
|
||||
if opt.LogDisabled {
|
||||
log.SetOutput(ioutil.Discard)
|
||||
}
|
||||
if len(opt.Exporters) == 0 {
|
||||
geziyor.opt.Exporters = []Exporter{exporter.JSONExporter{}}
|
||||
}
|
||||
if opt.MaxBodySize == 0 {
|
||||
geziyor.opt.MaxBodySize = 1024 * 1024 * 1024 // 1GB
|
||||
}
|
||||
@ -189,7 +190,15 @@ func (g *Geziyor) Do(req *http.Request, callback func(resp *Response)) {
|
||||
|
||||
// Export Functions
|
||||
for _, exp := range g.opt.Exporters {
|
||||
go exp.Export(response.Exports)
|
||||
go exp.Export(&response)
|
||||
}
|
||||
|
||||
// Drain exports chan if no exporters added
|
||||
if len(g.opt.Exporters) == 0 {
|
||||
go func() {
|
||||
for range response.Exports {
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
// Callbacks
|
||||
|
Reference in New Issue
Block a user