-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsoup_selenium.py
263 lines (238 loc) · 9.52 KB
/
soup_selenium.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
from string import digits
from helpers import only_digits
class SoupSelenium:
@staticmethod
def austria(soup):
def condition(tag):
if tag is None:
return False
return tag.name == 'div' and \
len(tag.contents) == 1 and \
'dpPositivGetestet' in tag.get('data-key', []) and \
'fit' in tag.get('class', [])
tag = soup.find(condition)
# print('tag', tag)
return tag, int(only_digits(tag.contents[0]))
@staticmethod
def estonia(soup):
def condition(tag):
if tag is None:
return False
return tag.name == 'div' and \
' '.join(tag.get('class', [])) == 'QFReadout QFUpperBound QFDisabled'
tag = soup.find(condition)
return tag.div, int(only_digits(tag.div.text))
@staticmethod
def italy(soup):
def condition(tag):
if tag is None:
return False
return tag.name == 'strong' and \
'Totale casi' in tag.text
tags = soup.find_all(condition)
assert len(tags) == 2
# print('TAGS')
# print(tags[0].parent.parent.parent.parent.find_next_sibling())
# print(tags[1].parent.parent.parent.parent.find_next_sibling())
tag = tags[0].parent.parent.parent.parent
number = tag.find_next_sibling().g.find_next_sibling().text
return tag.parent, int(only_digits(number))
@staticmethod
def israel(soup):
def condition(tag):
if tag is None:
return False
# 'נפטרים מצטבר' in tag.contents[0] # deaths
return tag.name == 'h3' and \
len(tag.contents) == 1 and \
'אחוז נבדקים חיוביים אתמול' in tag.contents[0] # percent of positive tests
tag = soup.find(condition).parent.parent
number = tag.find_next_sibling().find('h4').text
return tag, str(number)
@staticmethod
def israel_2022_01_30(soup):
def condition_outer(tag):
if tag is None:
return False
return tag.name == 'h3' and \
len(tag.contents) == 1 and \
'מאומתים חדשים אתמול' in tag.contents[0]
def condition_inner(tag):
if tag is None:
return False
return tag.name == 'span' and \
len(tag.contents) == 1 and \
'סה"כ' in tag.contents[0]
tag_outer = soup.find(condition_outer)
tag_outer = tag_outer.parent.parent.parent.parent
tag_inner = tag_outer.find(condition_inner)
number = tag_inner.find_previous_sibling().contents[0]
return tag_inner.parent, int(only_digits(number))
@staticmethod
def kosovo_old(soup):
def condition(tag):
if tag is None:
return False
return tag.name == 'h5' and \
len(tag.contents) == 1 and \
'Raste' in tag.contents[0]
tags = soup.find_all(condition)
return tags[1].parent, int(only_digits(tags[1].parent.h3.contents[0]))
@staticmethod
def kosovo(soup):
def condition(tag):
if tag is None:
return False
return tag.name == 'div' and \
'kpi-label' in tag.get('class', []) and \
'Gjithsej' in tag.text
tag = soup.find(condition)
return tag.parent, int(only_digits(tag.find_next_sibling().text))
@staticmethod
def latvia(soup):
def condition(tag):
if tag is None:
return False
return tag.name == 'span' and \
len(tag.contents) == 1 and \
'Saslimušo skaits' in tag.contents[0]
tag = soup.find(condition)
number = tag.parent.find_next_sibling().find(
lambda tag: tag.name == 'strong'
).contents[0]
return tag.parent.parent, int(only_digits(number))
@staticmethod
def lithuania(soup):
def condition(tag):
if tag is None:
return False
# Before 2022-02-06: 'Iš viso buvusių/esamų atvejų skaičius' in tag.contents[0]
return tag.name == 'span' and \
len(tag.contents) == 1 and \
'Iš viso buvusių/esamų' in tag.contents[0] and \
'skaičius' in tag.contents[0]
tag = soup.find(condition)
number = tag.parent.parent.td.span.contents[0]
return tag.parent.parent, int(only_digits(number))
@staticmethod
def montenegro(soup):
def condition(tag):
return tag.name == 'div' and \
tag.get('class', [''])[0] == 'InfographicEditor-Contents-Item' and \
len(tag.find_all(condition_inner)) > 0
def condition_inner(tag):
return tag.name == 'span' and \
len(tag.contents) == 1 and \
'UKUPAN BROJ OBOLJELIH' in tag.contents[0]
def condition_number(tag):
return tag.name == 'div' and \
'igc-textual-text' in tag.get('class', []) and \
'innertext' in tag.get('class', [])
tag = soup.find(condition)
return tag, int(only_digits(tag.find(condition_number).div.contents[0]))
@staticmethod
def poland(soup):
def condition(tag):
# Before 2022-02
# 'osoby zakażone od 4 marca 2020' in tag.contents[0]
return tag.name == 'strong' and \
len(tag.contents) == 1 and \
'od 4 marca 2020' in tag.contents[0]
tag = soup.find(condition)
tag = tag.parent.parent.parent
number_tag = \
tag.p.find_next_sibling().find_next_sibling().span.strong.span
number = number_tag.contents[1]
return tag, int(only_digits(number))
@staticmethod
def portugal(soup):
def condition(tag):
return tag.name == 'text' and \
'Confirmados' in tag.text
tag = soup.find(condition)
tag = tag.parent.parent.parent
number = tag.find_next_sibling().svg.g.find_next_sibling().text
return tag.parent, int(only_digits(number))
@staticmethod
def romania(soup):
def condition(tag):
return tag.name == 'div' and \
' '.join(tag.get('class', [''])) == \
'responsive-text flex-vertical flex-fix allow-shrink ' \
'indicator-top-text' and \
len(tag.find_all(condition_inner)) > 0
# 'flex-justify-center widget-body flex-fluid full-width ' \
# 'flex-vertical overflow-y-hidden overflow-x-hidden' and \
def condition_inner(tag):
return tag.name == 'text' and \
len(tag.contents) == 1 and \
'Total cazuri confirmate' in tag.contents[0]
tag = soup.find(condition).parent
number = \
tag.div.find_next_sibling().g.find_next_sibling().text
# tag.div.div.find_next_sibling().g.find_next_sibling().svg.text
return tag, int(only_digits(number))
@staticmethod
def united_kingdom(soup):
def condition(tag):
if tag is None:
return False
return tag.name == 'a' and \
'value-item-people_tested_positive-total-cumcasesbypublishdate-1_modal' in tag.get('id', '')
tags = soup.find_all(condition)
assert len(tags) == 1
return tags[0], int(only_digits(tags[0].contents[0]))
# AFRO
@staticmethod
def botswana(soup):
def condition(tag):
if tag is None:
return False
return tag.name == 'div' and \
'kpi-label' in tag.get('class', []) and \
'Total Confirmed Botswana Cases' in tag.text
tag = soup.find(condition)
total = only_digits(tag.find_next_sibling().text)
return tag.parent, int(total)
@staticmethod
def cape_verde(soup):
def condition(tag):
if tag is None:
return False
return tag.name == 'svg' and \
'Nº de Casos Confirmados' in tag.get('aria-label', '') and \
'.' in tag.get('aria-label', '') and \
'(' not in tag.get('aria-label', '')
tag = soup.find(condition)
return tag, int(only_digits(tag['aria-label']))
@staticmethod
def gabon(soup):
def condition(tag):
if tag is None:
return False
return tag.name == 'strong' and \
'CAS CONFIRMÉS' in tag.text
tag = soup.find(condition).parent.parent.parent
total = tag.find_next_sibling().text
return tag.parent, int(only_digits(total))
@staticmethod
def gambia(soup):
def condition(tag):
if tag is None:
return False
return tag.name == 'svg' and \
'Total Cases' in tag.get('aria-label', '') and \
'.' in tag.get('aria-label', '')
tag = soup.find(condition)
return tag, int(only_digits(tag['aria-label']))
@staticmethod
def zambia(soup):
def condition(tag):
if tag is None:
return False
return tag.name == 'div' and \
'title text-center' == ' '.join(tag.get('class', [])) and \
'Total in Zambia' in tag.text
tag = soup.find(condition)
total = tag.find_next_sibling().find_next_sibling().h3.text
return tag, int(only_digits(total))