From d0d606419f2c58da4412bd7b947dd270432c7371 Mon Sep 17 00:00:00 2001 From: Julien Riou Date: Mon, 19 Jul 2021 13:15:02 +0200 Subject: [PATCH] feat: Add limited cdiscount.com support (#31) - Only the first products are parsed - Notifications not sent because only available products are listed and the very first discovery doesn't send a notification to avoid false positives - Products stay available forever unless there is a retention period configured because unavailable products are not listed Signed-off-by: Julien Riou --- parser_url.go | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/parser_url.go b/parser_url.go index 16957b7..e2bd16a 100644 --- a/parser_url.go +++ b/parser_url.go @@ -80,6 +80,8 @@ func createQuery(shopName string, url string) (string, error) { switch shopName { case "cybertek.fr": return createQueryForCybertek(url), nil + case "cdiscount.com": + return createQueryForCdiscount(url), nil case "ldlc.com": return createQueryForLDLC(url), nil case "materiel.net": @@ -459,3 +461,38 @@ FOR el IN ELEMENTS(doc, "div.vs-product-list div.vs-product-list-item") ` return q } + +/* + * TODO: + * - list next products by triggering browser events and wait for them to load + * - list unavailable products + * - add pagination + */ +func createQueryForCdiscount(url string) string { + q := ` +LET page = '` + url + `' +LET doc = DOCUMENT(page, {driver: "cdp"}) + +WAIT_ELEMENT(doc, '.lpMain') +WAIT_ELEMENT(doc, '#pager') + +LET main = ELEMENT(doc, '.lpMain') + +FOR product IN ELEMENTS(main, '.lpTdgProduct') + // remove "carte graphique" and product identifier from name + LET title = REGEX_REPLACE(ELEMENT(product, '.prdtBILTit'), '(?i)carte graphique | \(.*\)', '') + LET a = ELEMENT(product, '.prdtBILA') + LET price = TO_FLOAT(REGEX_REPLACE(INNER_TEXT(ELEMENT(product, '.prdtBILPrice .price')), '€', '.')) + LET price_currency = 'EUR' + LET available = ELEMENT_EXISTS(product, '.btGreen') + RETURN { + 'name': title, + 'url': a.attributes.href, + 'price': price, + 'price_currency': price_currency, + 'available': available + } +) +` + return q +}