summaryrefslogtreecommitdiff
path: root/whiskyworld.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 /whiskyworld.go
parentfe12a1d41d74ac55dc3c1b27821375541ee5f2b2 (diff)
downloadalkobote-4f7a9316da8e19fa9466ee377148c7d07bf39fd9.tar.gz
Data from all shops are now saved in a data structure.
Diffstat (limited to 'whiskyworld.go')
-rw-r--r--whiskyworld.go39
1 files changed, 28 insertions, 11 deletions
diff --git a/whiskyworld.go b/whiskyworld.go
index 734c9f2..65bbacd 100644
--- a/whiskyworld.go
+++ b/whiskyworld.go
@@ -1,14 +1,16 @@
package main
import (
- "fmt"
"log"
"strings"
"github.com/gocolly/colly"
)
-func ScrapeWhiskyworld() {
+func ScrapeWhiskyworld() []Angebot {
+
+ Whiskys := []Angebot{}
+
c := colly.NewCollector(
colly.AllowedDomains("whiskyworld.de"),
colly.AllowedDomains("www.whiskyworld.de"),
@@ -16,28 +18,43 @@ func ScrapeWhiskyworld() {
c.OnHTML(".product-item", func(e *colly.HTMLElement) {
+ W := Angebot{}
+
whisky_name_part1 := e.ChildText("h3")
whisky_name_part2 := e.ChildText(".item-description")
- whisky_name := whisky_name_part1 + " " + whisky_name_part2
+ W.Name = whisky_name_part1 + " " + whisky_name_part2
- whisky_url := "https://www.whiskyworld.de/" + strings.TrimPrefix(e.ChildAttr("a", "href"), "../")
- log.Println(whisky_name)
- log.Println(whisky_url)
+ W.Url = "https://www.whiskyworld.de/" + strings.TrimPrefix(e.ChildAttr("a", "href"), "../")
regular_price_noisy := e.ChildText(".offer")
regular_price := strings.TrimSuffix(strings.TrimPrefix(regular_price_noisy, "statt "), " €*")
- discounted_price := e.ChildText(".uvp")
- log.Println(strings.TrimSuffix(discounted_price, " €") + "€")
- log.Println(regular_price + "€")
+ var err error
+
+ W.Original_price, err = sanitize_price(regular_price)
+ if err != nil {
+ log.Fatal(err)
+ return
+ }
- log.Println("https:" + e.ChildAttr("img", "src"))
+ W.Discounted_price, err = sanitize_price(e.ChildText(".uvp"))
+ if err != nil {
+ log.Fatal(err)
+ return
+ }
- fmt.Println("")
+ W.Image_url = "https:" + e.ChildAttr("img", "src")
+
+ W.Shop = "Whisky World"
+ W.Spirit_type = "Whisky"
+
+ Whiskys = append(Whiskys, W)
})
c.Visit("https://www.whiskyworld.de/themen/sonderangebote?ft=%257B%2522produkt_kategorie%2522:%2522Blended%2BMalt%2522%257D")
c.Visit("https://www.whiskyworld.de/themen/sonderangebote?ft=%257B%2522produkt_kategorie%2522:%2522Blended%2BWhiskies%2522%257D")
c.Visit("https://www.whiskyworld.de/themen/sonderangebote?ft=%257B%2522produkt_kategorie%2522:%2522Single%2BMalt%2522%257D")
+
+ return Whiskys
}