From be44288ef96fda621ff1d9dc139835eb4867a36b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Vizcaino?= Date: Mon, 8 May 2017 09:30:14 +0200 Subject: [PATCH] Update scrape rules following site layout changes --- auvieux-scraper.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/auvieux-scraper.go b/auvieux-scraper.go index 5c1bd1a..6c612ea 100644 --- a/auvieux-scraper.go +++ b/auvieux-scraper.go @@ -5,6 +5,7 @@ import ( "os" "regexp" "strconv" + "strings" "github.com/PuerkitoBio/goquery" ) @@ -23,8 +24,8 @@ type product struct { func convertPrice(pstr string) (float64, error) { // Remove trailing ' €' - re := regexp.MustCompile(`^(\d+),(\d+).*$`) - s := re.ReplaceAllString(pstr, "$1.$2") + re := regexp.MustCompile(`^(\d+)€(\d+)?.*$`) + s := re.ReplaceAllString(strings.TrimSpace(pstr), "$1.$2") return strconv.ParseFloat(s, 32) } @@ -35,8 +36,8 @@ func scrapeProduct(id string) (*product, error) { return nil, err } - name := doc.Find(".product-name > a").First().Text() - priceStr := doc.Find(".regular-price .price").First().Text() + name := doc.Find("span.product-list-name").First().Text() + priceStr := doc.Find("span.price-content-container > span.orangeColor").First().Text() price, err := convertPrice(priceStr) if err != nil {