summaryrefslogtreecommitdiff
path: root/whiskyzone.go
blob: 10b996b0a79c3fd8f185ac90136c137a50caeac5 (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
package main

import (
	"fmt"
	"log"
	"regexp"

	"github.com/gocolly/colly"
)

func ScrapeWhiskyzone() {
	c := colly.NewCollector(
		colly.AllowedDomains("whiskyzone.de"),
		colly.AllowedDomains("www.whiskyzone.de"),
	)

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

		whisky_name := e.ChildAttr("a", "title")
		whisky_url := e.ChildAttr("a", "href")
		log.Println(whisky_name)
		log.Println(whisky_url)
		price_discount_noisy := e.ChildText(".price--default")
		price_regular_noisy := e.ChildText(".price--discount")

		r, err := regexp.Compile("[0-9]+(,[0-9]{1,2})")
		if err != nil {
			log.Fatal(err)
		}
		log.Println(r.FindString(price_discount_noisy) + "€")
		log.Println(r.FindString(price_regular_noisy) + "€")

		e.ForEach(".image--media", func(i int, e *colly.HTMLElement) {
			log.Println(e.ChildAttr("img", "src"))
		})

		fmt.Println("")
	})

	c.Visit("https://www.whiskyzone.de/widgets/emotion/index/emotionId/248/controllerName/listing")
}

func main() {
	ScrapeWhiskyzone()
}