From 4f7a9316da8e19fa9466ee377148c7d07bf39fd9 Mon Sep 17 00:00:00 2001 From: horus_arch Date: Sun, 4 Feb 2018 20:54:58 +0100 Subject: Data from all shops are now saved in a data structure. --- whic.go | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) (limited to 'whic.go') 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 } -- cgit v1.2.3