package main import ( "log" "regexp" "strings" "github.com/gocolly/colly" ) func ScrapeWhiskysitenl(shop Shop) []Angebot { Whiskys := []Angebot{} c := colly.NewCollector( colly.AllowedDomains("whiskysite.nl"), colly.AllowedDomains("www.whiskysite.nl"), ) c.OnHTML(".product-block", func(e *colly.HTMLElement) { W := Angebot{} whisky_name := e.ChildAttr("img", "alt") whisky_url := e.ChildAttr("a", "href") W.Name = whisky_name W.Url = whisky_url regular_price := e.ChildText(".price-old") price_discount_noisy := e.ChildText(".product-block-price") r, err := regexp.Compile("[0-9]+(,[0-9]{1,2})") if err != nil { log.Fatal(err) } discounted_price := r.FindString(strings.Trim(strings.TrimPrefix(price_discount_noisy, regular_price), "")) W.Original_price, err = convert_price(regular_price) if err != nil { //log.Println(W.Name, err) return } W.Discounted_price, err = convert_price(discounted_price) if err != nil { //log.Println(W.Name, err) return } W.Image_url = e.ChildAttr("img", "src") W.Shop = shop.Id W.Spirit_type = "Whisky" Whiskys = append(Whiskys, W) }) c.Visit("https://www.whiskysite.nl/en/specials/?limit=100") return Whiskys }