-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
74 lines (60 loc) · 1.57 KB
/
main.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
67
68
69
70
71
72
73
74
package main
import (
// "crypto/tls"
"fmt"
// "io/ioutil"
"log"
"net/http"
"net/http/cookiejar"
// "net/url"
// "strconv"
"strings"
// "text/scanner"
"golang.org/x/net/publicsuffix"
// third-party libraries
"github.com/PuerkitoBio/goquery"
)
// fatal if there is an error
func checkErr(err error) {
if err != nil {
log.Fatal(err)
}
}
func retrieveSizeDesc(uri string) {
fmt.Printf("uri is: %s\n", uri)
options := cookiejar.Options{
PublicSuffixList: publicsuffix.List,
}
jar, err := cookiejar.New(&options)
checkErr(err)
client := http.Client{Jar: jar}
// Load the URL
// res, err := http.Get(uri)
res, err := client.Get(uri)
checkErr(err)
defer res.Body.Close()
/*
body, err := ioutil.ReadAll(res.Body)
checkErr(err)
fmt.Println("before body is:\n", string(body))
*/
// use utfBody using goquery
// doc, err := goquery.NewDocumentFromReader(utfBody)
// doc, err := goquery.NewDocument(uri)
doc, err := goquery.NewDocumentFromResponse(res)
// doc, err := goquery.NewDocumentFromResponse(res)
checkErr(err)
fmt.Println("doc MORE is:\n", doc)
// fmt.Println("doc.Contents is:\n", doc.Contents())
fmt.Println("about to find MORE stuff\n")
doc.Find("#information").Each(func(i int, s *goquery.Selection) {
desc := strings.TrimSpace(s.Find(".productText p").First().Text())
fmt.Println("prod desc is: ", desc)
// fruitItem.description = desc
// fruitOutQueue <- fruitItem
})
}
func main() {
uri := "http://www.sainsburys.co.uk/shop/gb/groceries/ripe---ready/sainsburys-conference-pears--ripe---ready-x4-%28minimum%29"
retrieveSizeDesc(uri)
}