Skip to content

Commit 9f5d53a

Browse files
committed
Refactored the code to make it more modular
1 parent 33a7556 commit 9f5d53a

File tree

1 file changed

+47
-10
lines changed

1 file changed

+47
-10
lines changed

Football_Player_Club_Info/main.py

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,23 @@
44
from bs4 import BeautifulSoup
55
import wikipediaapi
66

7-
wiki_lang = wikipediaapi.Wikipedia('en',extract_format=wikipediaapi.ExtractFormat.HTML)
8-
wiki_page = wiki_lang.page('Christiano Ronaldo')
9-
page_html_text = wiki_page.text
10-
soup = BeautifulSoup(page_html_text, "lxml")
11-
def print_sections(sections, level=0):
12-
for s in sections:
13-
if 'Club career' in s.title:
14-
print(s.title)
15-
#print("%s: %s - %s" % ("*" * (level + 1), s.title, s.text[0:100]))
7+
8+
9+
class myScraper:
10+
11+
#Initializing the Constructor
12+
def __init__(self, player):
13+
14+
self.wiki_lang = wikipediaapi.Wikipedia('en',extract_format=wikipediaapi.ExtractFormat.HTML)
15+
self.wiki_page = self.wiki_lang.page(player)
16+
self.page_html_text = self.wiki_page.text
17+
self.soup = BeautifulSoup(self.page_html_text, "lxml")
18+
self.player = player
19+
20+
def get_club_details(self,sections, level=0):
21+
for s in sections:
22+
if 'Club career' in s.title:
23+
print(s.title)
1624
for s in s.sections:
1725
level=level + 1
1826
print(s.title)
@@ -22,6 +30,35 @@ def print_sections(sections, level=0):
2230
for s in s.sections:
2331
level = level+1
2432
print(s.title)
33+
34+
def execute(self):
35+
self.get_club_details(self.wiki_page.sections, level=0)
36+
37+
38+
39+
# def print_sections(sections, level=0):
40+
# for s in sections:
41+
# if 'Club career' in s.title:
42+
# print(s.title)
43+
# #print("%s: %s - %s" % ("*" * (level + 1), s.title, s.text[0:100]))
44+
# for s in s.sections:
45+
# level=level + 1
46+
# print(s.title)
47+
# if(s.sections is None):
48+
# return
49+
# else:
50+
# for s in s.sections:
51+
# level = level+1
52+
# print(s.title)
2553

2654
#break
27-
print_sections(wiki_page.sections)
55+
# print_sections(wiki_page.sections)
56+
57+
def main():
58+
player = input("Please Enter the player Info")
59+
my_scraper_obj = myScraper(player)
60+
my_scraper_obj.execute()
61+
62+
if __name__ == '__main__':
63+
main()
64+

0 commit comments

Comments
 (0)