summaryrefslogtreecommitdiff
path: root/crawler/shop_whiskyworld.go
blob: e07c42f4fc0d84f17018bbb8e53a4fc4f5f9030a (plain)
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
package main

import (
	"log"
	"strings"

	"github.com/gocolly/colly"
)

func ScrapeWhiskyworld(shop Shop) []Angebot {

	Whiskys := []Angebot{}

	c := colly.NewCollector(
		colly.AllowedDomains("whiskyworld.de"),
		colly.AllowedDomains("www.whiskyworld.de"),
	)

	c.OnHTML(".product-item", func(e *colly.HTMLElement) {

		W := Angebot{}

		whisky_name_part1 := e.ChildText("h3")
		whisky_name_part2 := e.ChildText(".item-description")

		W.Name = whisky_name_part1 + " " + whisky_name_part2

		W.Url = "https://www.whiskyworld.de/" + strings.TrimPrefix(e.ChildAttr("a", "href"), "../")

		regular_price_noisy := e.ChildText(".offer")
		regular_price := strings.TrimSuffix(strings.TrimPrefix(regular_price_noisy, "statt "), " €*")

		var err error

		W.Original_price, err = sanitize_price(regular_price)
		if err != nil {
			log.Fatal(err)
			return
		}

		W.Discounted_price, err = sanitize_price(e.ChildText(".uvp"))
		if err != nil {
			log.Fatal(err)
			return
		}

		W.Image_url = "https:" + e.ChildAttr("img", "src")

		W.Shop = shop.Id
		W.Spirit_type = "Whisky"

		Whiskys = append(Whiskys, W)
	})

	c.Visit("https://www.whiskyworld.de/themen/sonderangebote?ft=%257B%2522produkt_kategorie%2522:%2522Blended%2BMalt%2522%257D")
	c.Visit("https://www.whiskyworld.de/themen/sonderangebote?ft=%257B%2522produkt_kategorie%2522:%2522Blended%2BWhiskies%2522%257D")
	c.Visit("https://www.whiskyworld.de/themen/sonderangebote?ft=%257B%2522produkt_kategorie%2522:%2522Single%2BMalt%2522%257D")

	return Whiskys
}