-
Notifications
You must be signed in to change notification settings - Fork 0
/
extractor.go
66 lines (55 loc) · 1.42 KB
/
extractor.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package extractor
const (
FromURL string = "url"
FromElement string = "element"
)
type Extractor interface {
Extract(url string) (*ExtractionResult, error)
}
func NewExtractor(config ExtractorConfig) Extractor {
if config.Mode == "static" {
return NewStaticExtractor(config)
}
return NewBrowserExtractor(config)
}
type ExtractorConfig struct {
Name string `json:"name"`
Pattern string `json:"pattern"`
ExampleURL string `json:"example_url"`
Mode string `json:"mode"`
Schemas []Schema `json:"schemas"`
}
type Schema struct {
Name string `json:"name"`
EntityType string `json:"entity_type"`
Selector string `json:"selector"`
Type string `json:"type"`
Fields []Field `json:"fields,omitempty"`
}
type Field struct {
Name string `json:"name"`
From string `json:"from"`
Selector string `json:"selector"`
Pattern string `json:"pattern"`
Type string `json:"type"`
Attribute string `json:"attribute,omitempty"`
Fields []Field `json:"fields,omitempty"`
}
type ExtractedItem map[string]interface{}
type ExtractionResult struct {
SchemaResults map[string]SchemaResult
Errors []ExtractionError
}
type SchemaResult struct {
Schema SchemaInfo
Items []ExtractedItem
}
type SchemaInfo struct {
Name string `json:"name"`
EntityType string `json:"entity_type"`
}
type ExtractionError struct {
Field string
Message string
URL string
}