summaryrefslogtreecommitdiff
path: root/whiskyzone.go
diff options
context:
space:
mode:
authorhorus_arch2018-02-04 20:54:58 +0100
committerhorus_arch2018-02-04 20:54:58 +0100
commit4f7a9316da8e19fa9466ee377148c7d07bf39fd9 (patch)
tree7c4fb5b35ea107d7379b4c7a601aa9a7d9d184d5 /whiskyzone.go
parentfe12a1d41d74ac55dc3c1b27821375541ee5f2b2 (diff)
downloadalkobote-4f7a9316da8e19fa9466ee377148c7d07bf39fd9.tar.gz
Data from all shops are now saved in a data structure.
Diffstat (limited to 'whiskyzone.go')
-rw-r--r--whiskyzone.go35
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
}