package main import ( "log" "strings" "github.com/gocolly/colly" ) func ScrapeWhiskyde(shop Shop) []Angebot { Shop_url := "https://www.whisky.de/shop/Aktuell/Sonderangebote/" Whiskys := []Angebot{} c := colly.NewCollector( colly.AllowedDomains("whisky.de"), colly.AllowedDomains("www.whisky.de"), ) c.OnHTML(".is-buyable", func(e *colly.HTMLElement) { if e.Request.URL.String() != Shop_url { return } W := Angebot{} whisky_name := e.ChildAttr("a", "title") W.Name = whisky_name whisky_url := strings.Replace(e.ChildAttr("a", "href"), "?&searchorigin=2", "", 1) W.Url = whisky_url var err error e.ForEach(".article-price-original", func(i int, e *colly.HTMLElement) { W.Original_price, err = convert_price(e.ChildText("del")) if err != nil { log.Fatal(err) } }) e.ForEach(".article-price", func(i int, e *colly.HTMLElement) { W.Discounted_price, err = convert_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") }) e.ForEach(".article-price-prefix", func(i int, e *colly.HTMLElement) { //W.Valid_until = e.ChildText(".article-price-special") }) e.ForEach(".article-amount", func(i int, e *colly.HTMLElement) { text_noisy := e.ChildText("span") if strings.Contains("Liter", text_noisy) { W.Volume, err = extract_volume(text_noisy) if err != nil { log.Fatal(err) } } else { W.Abv, err = extract_abv(text_noisy) if err != nil { log.Fatal(err) } } }) if W.Volume == 0 { log.Println(W.Name + " kein Volume erkannt") } if W.Abv == 0 { log.Println(W.Name + " kein Abv erkannt") } W.Shop = shop.Id W.Spirit_type = "Whisky" W.Base_price, err = convert_price(e.ChildText(".article-unitprice-default")) if err != nil { log.Fatal(err) } Whiskys = append(Whiskys, W) }) c.Visit(Shop_url) return Whiskys }