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
|
package main
import (
"log"
"regexp"
"strings"
"github.com/gocolly/colly"
)
func ScrapeWhiskysitenl(shop Shop) []Angebot {
Whiskys := []Angebot{}
c := colly.NewCollector(
colly.AllowedDomains("whiskysite.nl"),
colly.AllowedDomains("www.whiskysite.nl"),
)
c.OnHTML(".product-block", func(e *colly.HTMLElement) {
W := Angebot{}
whisky_name := e.ChildAttr("img", "alt")
whisky_url := e.ChildAttr("a", "href")
W.Name = whisky_name
W.Url = whisky_url
regular_price := e.ChildText(".price-old")
price_discount_noisy := e.ChildText(".product-block-price")
r, err := regexp.Compile("[0-9]+(,[0-9]{1,2})")
if err != nil {
log.Fatal(err)
}
discounted_price := r.FindString(strings.Trim(strings.TrimPrefix(price_discount_noisy, regular_price), ""))
W.Original_price, err = sanitize_price(regular_price)
if err != nil {
//log.Println(W.Name, err)
return
}
W.Discounted_price, err = sanitize_price(discounted_price)
if err != nil {
//log.Println(W.Name, err)
return
}
W.Image_url = e.ChildAttr("img", "src")
W.Shop = shop.Id
W.Spirit_type = "Whisky"
Whiskys = append(Whiskys, W)
})
c.Visit("https://www.whiskysite.nl/en/specials/?limit=100")
return Whiskys
}
|