From 3a162d92d34c0396ddbca64444b8c2044cc88df9 Mon Sep 17 00:00:00 2001 From: unwox Date: Wed, 5 Mar 2025 20:38:40 +0600 Subject: add yoceramics parser --- parser/yoceramics.fnl | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 parser/yoceramics.fnl (limited to 'parser/yoceramics.fnl') diff --git a/parser/yoceramics.fnl b/parser/yoceramics.fnl new file mode 100644 index 0000000..af0ec0a --- /dev/null +++ b/parser/yoceramics.fnl @@ -0,0 +1,61 @@ +(local peg + (if (pick-values 1 (pcall require :lpeg)) + (require :lpeg) + (require :lpeglj))) +(local parser (require :parser.parser)) +(local number (require :lib.number)) +(local fetcher (require :fetcher)) + +(fn format-url [path page] + (.. "https://yoceramics.ru/product-category/" path + (if (= 1 page) "" (.. "/page/" page)) "/?per_page=36")) + +(local product-peg + (* + (parser.anywhere "class=\"product-image-link\"") + (parser.anywhere (* "src=\"" (peg.Cg (parser.till "\"") :image) "\"")) + (parser.anywhere + (parser.tag :h3 {:class "wd-entities-title"} + (parser.tag :a {:href (peg.Cg (parser.till "\"") :url)} + (peg.Cg (parser.till "") :title)))) + (parser.anywhere + (parser.tag :span {:class "woocommerce-Price-amount amount"} + (parser.tag :bdi {} + (* + (peg.Cg (parser.till " ") :price) + (parser.till ""))))) + (parser.anywhere + (parser.tag :div {:class "hover-content-inner wd-more-desc-inner"} + (* + (parser.maybe parser.pegs.spaces) + (peg.Cg (parser.till "") :description)))) + (parser.anywhere (parser.tag :span {} "В корзину")))) + +(fn normalize [product] + {:site "yoceramics" + :title product.title + :url product.url + :description product.description + :image product.image + :year nil + :price (number.string->number product.price) + :weight nil + :volume (parser.guess-volume product.description) + :price-per nil}) + +(fn products [] + (fetcher.from-html + [{:path "gajvani" :tags ["Посуда" "Керамика" "Гайвань"]} + {:path "vazy" :tags ["Посуда" "Керамика" "Ваза"]} + {:path "kensuj" :tags ["Посуда" "Керамика" "Кенсуй"]} + {:path "pialy-i-chashi" :tags ["Посуда" "Керамика" "Пиала"]} + {:path "tyavany" :tags ["Посуда" "Керамика" "Тяван"]} + {:path "chajniki" :tags ["Посуда" "Керамика" "Чайник"]} + {:path "chahai" :tags ["Посуда" "Керамика" "Чахай"]} + {:path "chajnye-prudiki" :tags ["Посуда" "Керамика" "Чайный пруд"]} + {:path "chahe" :tags ["Посуда" "Керамика" "Чахэ"]}] + format-url + product-peg + normalize)) + +{:products products :title "yo_ceramics" :url "https://www.yoceramics.ru"} -- cgit v1.2.3