-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelpers.py
50 lines (43 loc) · 1.56 KB
/
helpers.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
""" Collection of helper functions """
def clean_leadership(soup):
"""clean soup object of leadership news article page"""
main = soup.find_all("div", class_="content-inner")
cleaned = main[0].get_text()
return cleaned
def clean_punch_or_sun(soup):
"""clean soup object of punch news article page"""
main = soup.find_all("div", class_="post-content")
cleaned = main[0].get_text()
return cleaned
def clean_pmnews(soup):
"""clean soup object of pmnews news article page"""
main = soup.find_all("div", class_="article-content")
cleaned = main[0].get_text()
return cleaned
def clean_dailytrust(soup):
"""clean soup object of pmnews news article page"""
main = soup.find_all("article", class_="article__body")
cleaned = main[0].get_text()
return cleaned
def clean_thisday(soup):
"""clean soup object of pmnews news article page"""
main = soup.find_all("div", class_="article-content")
cleaned = main[0].get_text()
return cleaned
def clean_allafrica(soup):
"""clean soup object of pmnews news article page"""
main = soup.find_all("div", class_="story-body")
if main == None or main == []:
text = soup.get_text()
stripped = text[4000:-1500]
cleaned = str(stripped).strip().replace('\n', '')
else:
# print(cleaned)
cleaned = main[0].get_text()
return cleaned
def generic_clean(soup):
"""clean soup object from other sources"""
cleaned = soup.get_text()
stripped = str(cleaned).strip().replace('\n', '')
print(stripped)
return stripped