forked from preetyverma20/Amazing-Python-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
64 lines (51 loc) · 1.77 KB
/
main.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
import pandas as pd
import requests
import urllib.request
from bs4 import BeautifulSoup
import wikipediaapi
class myScraper:
# Initializing the Constructor
def __init__(self, player):
self.wiki_lang = wikipediaapi.Wikipedia(
'en', extract_format=wikipediaapi.ExtractFormat.HTML)
self.wiki_page = self.wiki_lang.page(player)
self.page_html_text = self.wiki_page.text
self.soup = BeautifulSoup(self.page_html_text, "lxml")
self.player = player
def get_club_details(self, sections, level=0):
for s in sections:
if 'Club career' in s.title:
print(s.title)
for s in s.sections:
level = level + 1
print(s.title)
if (s.sections is None):
return
else:
for s in s.sections:
level = level + 1
print(s.title)
def execute(self):
self.get_club_details(self.wiki_page.sections, level=0)
# def print_sections(sections, level=0):
# for s in sections:
# if 'Club career' in s.title:
# print(s.title)
# #print("%s: %s - %s" % ("*" * (level + 1), s.title, s.text[0:100]))
# for s in s.sections:
# level=level + 1
# print(s.title)
# if(s.sections is None):
# return
# else:
# for s in s.sections:
# level = level+1
# print(s.title)
# break
# print_sections(wiki_page.sections)
def main():
player = input("Please Enter the player Info")
my_scraper_obj = myScraper(player)
my_scraper_obj.execute()
if __name__ == '__main__':
main()