diff options
| author | horus_arch | 2018-02-04 20:54:58 +0100 |
|---|---|---|
| committer | horus_arch | 2018-02-04 20:54:58 +0100 |
| commit | 4f7a9316da8e19fa9466ee377148c7d07bf39fd9 (patch) | |
| tree | 7c4fb5b35ea107d7379b4c7a601aa9a7d9d184d5 /whic.go | |
| parent | fe12a1d41d74ac55dc3c1b27821375541ee5f2b2 (diff) | |
| download | alkobote-4f7a9316da8e19fa9466ee377148c7d07bf39fd9.tar.gz | |
Data from all shops are now saved in a data structure.
Diffstat (limited to 'whic.go')
| -rw-r--r-- | whic.go | 33 |
1 files changed, 25 insertions, 8 deletions
@@ -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 } |
