-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_matches.py
65 lines (50 loc) · 1.64 KB
/
get_matches.py
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
62
63
64
65
from html.parser import HTMLParser
from requests import get
class MyHTMLParser(HTMLParser):
def __init__(self):
HTMLParser.__init__(self)
self.recording = 0
self.data = []
def handle_starttag(self, tag, attrs):
if tag == 'ul':
# print("ul found", attrs)
for name, value in attrs:
if name == 'class' and 'no-list-style matches-round-1' in value:
# print(value)
self.recording = 1
def handle_endtag(self, tag):
if tag == 'ul':
self.recording -= 1
def handle_data(self, data):
if self.recording == 1:
if len(data.strip()) <= 0 or data.strip == '-' or data.strip == 'vs':
pass
else:
# print(data.strip())
self.data.append(data.strip())
class Match:
def __init__(self, time, home, away):
self.time = time
self.home = home
self.away = away
def grab_matches():
p = MyHTMLParser()
req = get(
'https://www.gamer.no/turneringer/telialigaen-counter-strike-go-hosten-2019/6095/kamper/')
p.feed(req.text)
return p.data
obj = {'time': '', 'home': '', 'away': ''}
matches = []
m = grab_matches()
for index in range(len(m)):
if index % 5 == 0:
obj['time'] = m[index]
if index % 5 == 1:
obj['home'] = m[index]
print(obj)
if index % 5 == 3:
obj['away'] = m[index]
p = Match(obj['time'], obj['home'], obj['away'])
matches.append(p)
for x in matches:
print("[{}] {} vs {} [*]".format(x.time, x.home, x.away))