diff options
Diffstat (limited to 'whiskyzone.go')
| -rw-r--r-- | whiskyzone.go | 35 |
1 files changed, 25 insertions, 10 deletions
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 } |
