From 9947cae94752e91cc41189315d65770502d38d02 Mon Sep 17 00:00:00 2001 From: Steve Dudenhoeffer Date: Fri, 10 Oct 2025 14:42:01 -0400 Subject: [PATCH] Refine selectors and enhance price parsing with logging Adjusted HTML selectors for improved compatibility and updated price parsing logic to handle additional formats. Added logging to provide better debugging insights during price extraction. --- sites/aislegopher/aislegopher.go | 4 ++-- sites/wegmans/wegmans.go | 12 +++++++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/sites/aislegopher/aislegopher.go b/sites/aislegopher/aislegopher.go index babb76c..9756850 100644 --- a/sites/aislegopher/aislegopher.go +++ b/sites/aislegopher/aislegopher.go @@ -62,13 +62,13 @@ func (c Config) GetItemFromURL(ctx context.Context, b extractor.Browser, u *url. return res, fmt.Errorf("failed to open page: %w", err) } - names := doc.Select("h2.h4") + names := doc.Select(".h4") if len(names) > 0 { res.Name, _ = names[0].Text() } - prices := doc.Select("h4.h2") + prices := doc.Select(".h2") if len(prices) > 0 { priceStr, _ := prices[0].Text() diff --git a/sites/wegmans/wegmans.go b/sites/wegmans/wegmans.go index f212de7..a2cbe25 100644 --- a/sites/wegmans/wegmans.go +++ b/sites/wegmans/wegmans.go @@ -4,6 +4,7 @@ import ( "context" "errors" "io" + "log/slog" "net/url" "strconv" "strings" @@ -80,23 +81,28 @@ func (c Config) GetItemPrice(ctx context.Context, b extractor.Browser, u *url.UR ID: id, } - titles := doc.Select("h1[data-test]") + titles := doc.Select("h1[data-testid]") if len(titles) != 0 { res.Name, _ = titles[0].Text() } - prices := doc.Select("span[data-test=\"amount\"] span:nth-child(1)") + prices := doc.Select("div.component--product-price:nth-child(1) > div:nth-child(1) > span:nth-child(1) > span:nth-child(2)") + slog.Info("prices", "len", len(prices)) if len(prices) != 0 { priceStr, _ := prices[0].Text() + slog.Info("price", "0", prices[0], "text", priceStr) priceStr = strings.ReplaceAll(priceStr, "$", "") priceStr = strings.ReplaceAll(priceStr, ",", "") + // if there's a "/" in the price, then it's in the format of like "1.99/ea", so split it off + priceStr = strings.Split(priceStr, "/")[0] price, _ := strconv.ParseFloat(priceStr, 64) + slog.Info("price", "0", prices[0], "text", priceStr, "price", price) res.Price = price } - unitPrices := doc.Select(`span[data-test="per-unit-price"]`) + unitPrices := doc.Select(`div.component--product-price:nth-child(1) span.price-per-unit`) if len(unitPrices) != 0 { unitPriceStr, _ := unitPrices[0].Text()