From 4f7a9316da8e19fa9466ee377148c7d07bf39fd9 Mon Sep 17 00:00:00 2001 From: horus_arch Date: Sun, 4 Feb 2018 20:54:58 +0100 Subject: Data from all shops are now saved in a data structure. --- whiskyzone.go | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) (limited to 'whiskyzone.go') diff --git a/whiskyzone.go b/whiskyzone.go index 274f3dd..dc4a047 100644 --- a/whiskyzone.go +++ b/whiskyzone.go @@ -1,14 +1,16 @@ package main import ( - "fmt" "log" "regexp" "github.com/gocolly/colly" ) -func ScrapeWhiskyzone() { +func ScrapeWhiskyzone() []Angebot { + + Whiskys := []Angebot{} + c := colly.NewCollector( colly.AllowedDomains("whiskyzone.de"), colly.AllowedDomains("www.whiskyzone.de"), @@ -16,10 +18,10 @@ func ScrapeWhiskyzone() { 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) + W := Angebot{} + + W.Name = e.ChildAttr("a", "title") + W.Url = e.ChildAttr("a", "href") price_discount_noisy := e.ChildText(".price--default") price_regular_noisy := e.ChildText(".price--discount") @@ -27,15 +29,28 @@ func ScrapeWhiskyzone() { if err != nil { log.Fatal(err) } - log.Println(r.FindString(price_discount_noisy) + "€") - log.Println(r.FindString(price_regular_noisy) + "€") + W.Discounted_price, err = sanitize_price(r.FindString(price_discount_noisy)) + if err != nil { + log.Fatal(err) + return + } + W.Original_price, err = sanitize_price(r.FindString(price_regular_noisy)) + if err != nil { + log.Fatal(err) + return + } e.ForEach(".image--media", func(i int, e *colly.HTMLElement) { - log.Println(e.ChildAttr("img", "src")) + W.Image_url = e.ChildAttr("img", "src") }) - fmt.Println("") + W.Shop = "Whiskyzone" + W.Spirit_type = "Whisky" + + Whiskys = append(Whiskys, W) }) c.Visit("https://www.whiskyzone.de/widgets/emotion/index/emotionId/248/controllerName/listing") + + return Whiskys } -- cgit v1.2.3