-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathseries_parser.py
94 lines (68 loc) · 2.22 KB
/
series_parser.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
from pprint import pprint
import bs4
class Parser:
"""
"""
def __init__(self, worker, season, html):
"""
:param worker:
:param season:
:param html:
"""
self.worker = worker
self.season = season
self.html = html
self.data = {}
self.do_work()
def do_work(self):
"""
:return:
"""
soup = bs4.BeautifulSoup(self.html, 'html.parser')
div = soup.find('div', {'class': 'list detail eplist'})
for i in div.contents:
# if type(i) is bs4.element.Tag:
if isinstance(i, bs4.element.Tag):
# print(type(i))
# print(i)
self.data_parsing(i)
# pprint(self.data)
if self.worker:
self.worker.data.update({self.season: self.data})
def data_parsing(self, i):
"""
:param i:
:return:
"""
series_n = i.contents[1].contents[1].contents[1].contents[3].text
series_n = series_n[series_n.find('Ep') + 2:]
if self.worker and series_n == '0':
self.worker.zero = True
try:
series_date = i.find('div', {'class': 'airdate'}).text.replace('\n', '').strip()
except:
series_date = ''
try:
series_rating = i.find('span', {'class': 'ipl-rating-star__rating'}).text.replace('\n', '').strip()
except:
series_rating = '0'
try:
series_votes = i.find('span', {'class': 'ipl-rating-star__total-votes'}).text.replace('\n',
'').strip()
except:
series_votes = ''
try:
series_title = i.find('a', {'itemprop': 'name'}).text.replace('\n', '').strip()
except:
series_title = ''
full_info = {
'date': series_date,
'rating': series_rating,
'votes': series_votes,
'title': series_title
}
self.data[series_n] = full_info
if __name__ == "__main__":
with open('imdbtst.html', encoding='utf-8') as f:
read_data = f.read()
Parser(None, 1, read_data)