summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhorus_arch2018-02-04 20:02:14 +0100
committerhorus_arch2018-02-04 20:02:14 +0100
commit0687b4217abf0c278bcab50de4edafec76da4a91 (patch)
treef14114b445b355468db14cd8143aac4a31720e63
parentc2ffa908a41ae8b4f8cd9471e2ecd927ece94631 (diff)
downloadalkobote-0687b4217abf0c278bcab50de4edafec76da4a91.tar.gz
Saves the data in a structured way.
-rw-r--r--main.go22
-rw-r--r--whiskyde.go27
2 files changed, 25 insertions, 24 deletions
diff --git a/main.go b/main.go
index 79f578b..3a8efa3 100644
--- a/main.go
+++ b/main.go
@@ -10,8 +10,8 @@ type Angebot struct {
Name string
Shop string
Url string
- Original_price string
- Discounted_price string
+ Original_price int
+ Discounted_price int
Image_url string
Spirit_type string
Valid_until string
@@ -30,15 +30,8 @@ func main() {
ScrapeWhic()
*/
- printName("Whisky.de")
W := ScrapeWhiskyde()
-
- output, err := json.Marshal(W)
- if err != nil {
- log.Fatal(err)
- }
-
- fmt.Println(string(output))
+ printName(W, "Whisky.de")
/*
printName("Whiskysite.nl")
@@ -55,8 +48,15 @@ func main() {
*/
}
-func printName(name string) {
+func printName(W []Angebot, name string) {
fmt.Println("-------------------")
fmt.Println("Sonderangebote von " + name)
fmt.Println("-------------------")
+
+ output, err := json.MarshalIndent(W, "", " ")
+ if err != nil {
+ log.Fatal(err)
+ }
+
+ fmt.Println(string(output))
}
diff --git a/whiskyde.go b/whiskyde.go
index 90032ba..62e30f1 100644
--- a/whiskyde.go
+++ b/whiskyde.go
@@ -1,8 +1,8 @@
package main
import (
- "fmt"
"log"
+ "strings"
"github.com/gocolly/colly"
)
@@ -18,37 +18,38 @@ func ScrapeWhiskyde() []Angebot {
c.OnHTML(".is-buyable", func(e *colly.HTMLElement) {
W := Angebot{}
-
whisky_name := e.ChildAttr("a", "title")
W.Name = whisky_name
- whisky_url := e.ChildAttr("a", "href")
+ whisky_url := strings.Replace(e.ChildAttr("a", "href"), "?&searchorigin=2", "", 1)
W.Url = whisky_url
- log.Println(whisky_name)
- log.Println(whisky_url)
+ var err error
e.ForEach(".article-price-original", func(i int, e *colly.HTMLElement) {
- W.Original_price = e.ChildText("del")
- log.Println(e.ChildText("del"))
+ W.Original_price, err = sanitize_price(e.ChildText("del"))
+ if err != nil {
+ log.Fatal(err)
+ }
})
e.ForEach(".article-price", func(i int, e *colly.HTMLElement) {
- W.Discounted_price = e.ChildText(".article-price-default")
- log.Println(e.ChildText(".article-price-default"))
+ W.Discounted_price, err = sanitize_price(e.ChildText(".article-price-default"))
+ if err != nil {
+ log.Fatal(err)
+ }
})
e.ForEach(".article-thumbnail", func(i int, e *colly.HTMLElement) {
W.Image_url = e.ChildAttr("img", "data-src")
- log.Println(e.ChildAttr("img", "data-src"))
})
e.ForEach(".article-price-prefix", func(i int, e *colly.HTMLElement) {
W.Valid_until = e.ChildText(".article-price-special")
- log.Println(e.ChildText(".article-price-special"))
})
- Whiskys = append(Whiskys, W)
+ W.Shop = "Whisky.de"
+ W.Spirit_type = "Whisky"
- fmt.Println("")
+ Whiskys = append(Whiskys, W)
})
c.Visit("https://www.whisky.de/shop/Aktuell/Sonderangebote/")