summaryrefslogtreecommitdiff
path: root/whic.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 /whic.go
parentfe12a1d41d74ac55dc3c1b27821375541ee5f2b2 (diff)
downloadalkobote-4f7a9316da8e19fa9466ee377148c7d07bf39fd9.tar.gz
Data from all shops are now saved in a data structure.
Diffstat (limited to 'whic.go')
-rw-r--r--whic.go33
1 files changed, 25 insertions, 8 deletions
diff --git a/whic.go b/whic.go
index ecbd109..fced386 100644
--- a/whic.go
+++ b/whic.go
@@ -1,7 +1,6 @@
package main
import (
- "fmt"
"log"
"strings"
@@ -9,23 +8,36 @@ import (
"github.com/gocolly/colly"
)
-func ScrapeWhic() {
+func ScrapeWhic() []Angebot {
+ Whiskys := []Angebot{}
+
c := colly.NewCollector(
colly.AllowedDomains("whic.de"),
)
c.OnHTML("li.item", func(e *colly.HTMLElement) {
+ W := Angebot{}
+
whisky_name := e.ChildAttr("a", "title")
whisky_url := e.ChildAttr("a", "href")
- log.Println(whisky_name)
- log.Println(whisky_url)
+
+ W.Name = whisky_name
+ W.Url = whisky_url
+
+ var err error
e.ForEach(".price-box", func(i int, e *colly.HTMLElement) {
e.ForEach(".old-price", func(i int, e *colly.HTMLElement) {
- log.Println(e.ChildText(".price"))
+ W.Original_price, err = sanitize_price(e.ChildText(".price"))
+ if err != nil {
+ log.Fatal(err)
+ }
})
e.ForEach(".special-price", func(i int, e *colly.HTMLElement) {
- log.Println(e.ChildText(".price"))
+ W.Discounted_price, err = sanitize_price(e.ChildText(".price"))
+ if err != nil {
+ log.Fatal(err)
+ }
})
})
@@ -38,10 +50,15 @@ func ScrapeWhic() {
if err != nil {
log.Fatal(err)
}
- log.Println(doc.Find("img").Attr("src"))
+ W.Image_url, _ = doc.Find("img").Attr("src")
+
+ W.Shop = "Whic"
+ W.Spirit_type = "Whisky"
- fmt.Println("")
+ Whiskys = append(Whiskys, W)
})
c.Visit("https://whic.de/angebote")
+
+ return Whiskys
}