blob: af0ec0aac056a505a2363df02f86f67848bd14bc (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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 "</a>") :title))))
(parser.anywhere
(parser.tag :span {:class "woocommerce-Price-amount amount"}
(parser.tag :bdi {}
(*
(peg.Cg (parser.till " ") :price)
(parser.till "</bdi>")))))
(parser.anywhere
(parser.tag :div {:class "hover-content-inner wd-more-desc-inner"}
(*
(parser.maybe parser.pegs.spaces)
(peg.Cg (parser.till "</div>") :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"}
|