(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"}