-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
51 lines (42 loc) · 1.63 KB
/
main.go
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
// Copyright (c) 2022 Orlov Boris onlycodergod@gmail.com.
// This file main.go is subject to the terms and
// conditions defined in file 'LICENSE', which is part of this project source code.
package main
import (
"strings"
"github.com/PuerkitoBio/goquery"
"github.com/geziyor/geziyor"
"github.com/geziyor/geziyor/client"
"github.com/geziyor/geziyor/export"
)
func main() {
geziyor.NewGeziyor(&geziyor.Options{
StartURLs: []string{"https://kinoteatr.ru/raspisanie-kinoteatrov/city/#"},
ParseFunc: parseMovies,
Exporters: []export.Exporter{&export.JSON{}},
}).Start()
}
func parseMovies(g *geziyor.Geziyor, r *client.Response) {
r.HTMLDoc.Find("div.shedule_movie").Each(func(i int, s *goquery.Selection) {
sessions := strings.Split(s.Find(".shedule_session_time").Text(), " \n ")
sessions = sessions[:len(sessions)-1]
for i := 0; i < len(sessions); i++ {
sessions[i] = strings.Trim(sessions[i], "\n ")
}
var description string
if href, ok := s.Find("a.gtm-ec-list-item-movie").Attr("href"); ok {
g.Get(r.JoinURL(href), func(_g *geziyor.Geziyor, _r *client.Response) {
description = _r.HTMLDoc.Find("span.announce p.movie_card_description_inform").Text()
description = strings.ReplaceAll(description, "\t", "")
description = strings.ReplaceAll(description, "\n", "")
description = strings.TrimSpace(description)
g.Exports <- map[string]interface{}{
"title": strings.TrimSpace(s.Find("span.movie_card_header.title").Text()),
"subtitle": strings.TrimSpace(s.Find("span.sub_title.shedule_movie_text").Text()),
"sessions": sessions,
"description": description,
}
})
}
})
}