diff options
| author | horus_arch | 2018-02-04 20:18:27 +0100 |
|---|---|---|
| committer | horus_arch | 2018-02-04 20:18:27 +0100 |
| commit | fe12a1d41d74ac55dc3c1b27821375541ee5f2b2 (patch) | |
| tree | 57f841f57fe8405e0461d7fd5a9c08787caa0cca /bottleworld.go | |
| parent | 0687b4217abf0c278bcab50de4edafec76da4a91 (diff) | |
| download | alkobote-fe12a1d41d74ac55dc3c1b27821375541ee5f2b2.tar.gz | |
Structures the crawler for bottleworld and mcwhisky.
Diffstat (limited to 'bottleworld.go')
| -rw-r--r-- | bottleworld.go | 33 |
1 files changed, 25 insertions, 8 deletions
diff --git a/bottleworld.go b/bottleworld.go index edba866..55ee47c 100644 --- a/bottleworld.go +++ b/bottleworld.go @@ -1,7 +1,6 @@ package main import ( - "fmt" "log" "regexp" // "strings" @@ -10,13 +9,17 @@ import ( "github.com/gocolly/colly" ) -func ScrapeBottleWord() { +func ScrapeBottleWord() []Angebot { + Whiskys := []Angebot{} + c := colly.NewCollector( colly.AllowedDomains("bottleworld.de"), colly.AllowedDomains("www.bottleworld.de"), ) c.OnHTML("li.item", func(e *colly.HTMLElement) { + W := Angebot{} + whisky_name := e.ChildText("h2 > a") matched, err := regexp.MatchString("Whiske?y", whisky_name) @@ -24,25 +27,39 @@ func ScrapeBottleWord() { log.Fatal(err) } if !matched { + //W.Spirit_type = "Anderes" return + } else { + W.Spirit_type = "Whisky" } whisky_url := e.ChildAttr("a", "href") - log.Println(whisky_name) - log.Println(whisky_url) + W.Name = whisky_name + W.Url = whisky_url 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) + } }) }) - log.Println(e.ChildAttr("img", "src")) + W.Image_url = e.ChildAttr("img", "src") - fmt.Println("") + W.Shop = "bottleworld.de" + W.Spirit_type = "Whisky" + + Whiskys = append(Whiskys, W) }) c.Visit("https://www.bottleworld.de/aktuelle-sonderpreise/show/all") + + return Whiskys } |
