diff options
Diffstat (limited to 'crawler/shop_whiskyzone.go')
| -rw-r--r-- | crawler/shop_whiskyzone.go | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/crawler/shop_whiskyzone.go b/crawler/shop_whiskyzone.go new file mode 100644 index 0000000..a9e73d0 --- /dev/null +++ b/crawler/shop_whiskyzone.go @@ -0,0 +1,56 @@ +package main + +import ( + "log" + "regexp" + + "github.com/gocolly/colly" +) + +func ScrapeWhiskyzone(shop Shop) []Angebot { + + Whiskys := []Angebot{} + + c := colly.NewCollector( + colly.AllowedDomains("whiskyzone.de"), + colly.AllowedDomains("www.whiskyzone.de"), + ) + + c.OnHTML(".product--info", func(e *colly.HTMLElement) { + + 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") + + r, err := regexp.Compile("[0-9]+(,[0-9]{1,2})") + if err != nil { + log.Fatal(err) + } + 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) { + W.Image_url = e.ChildAttr("img", "src") + }) + + W.Shop = shop.Id + W.Spirit_type = "Whisky" + + Whiskys = append(Whiskys, W) + }) + + c.Visit("https://www.whiskyzone.de/widgets/emotion/index/emotionId/248/controllerName/listing") + + return Whiskys +} |
