diff options
| -rw-r--r-- | main.go | 22 | ||||
| -rw-r--r-- | whiskyde.go | 27 |
2 files changed, 25 insertions, 24 deletions
@@ -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/") |
