-
Notifications
You must be signed in to change notification settings - Fork 11
/
extract.go
38 lines (30 loc) · 953 Bytes
/
extract.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
package scraperboard
import (
"io"
"net/http"
"github.com/mitchellh/mapstructure"
)
// ExtractFromURL scrapes the HTML served in the specified URL into a golang struct
func (s *Scraper) ExtractFromURL(url string, target interface{}) (err error) {
res, err := s.ScrapeFromURL(url)
if err != nil {
return
}
return mapstructure.Decode(res, target)
}
// ExtractFromResponse scrapes the HTML served in the specified http response into a golang struct
func (s *Scraper) ExtractFromResponse(response *http.Response, target interface{}) (err error) {
res, err := s.ScrapeFromResponse(response)
if err != nil {
return
}
return mapstructure.Decode(res, target)
}
// ExtractFromReader scrapes the HTML served in the specified URL into a golang struct
func (s *Scraper) ExtractFromReader(r io.Reader, target interface{}) (err error) {
res, err := s.ScrapeFromReader(r)
if err != nil {
return
}
return mapstructure.Decode(res, target)
}