Amazing-Python-Scripts
64 строки · 1.8 Кб
1import pandas as pd2import requests3import urllib.request4from bs4 import BeautifulSoup5import wikipediaapi6
7
8class myScraper:9
10# Initializing the Constructor11def __init__(self, player):12
13self.wiki_lang = wikipediaapi.Wikipedia(14'en', extract_format=wikipediaapi.ExtractFormat.HTML)15self.wiki_page = self.wiki_lang.page(player)16self.page_html_text = self.wiki_page.text17self.soup = BeautifulSoup(self.page_html_text, "lxml")18self.player = player19
20def get_club_details(self, sections, level=0):21for s in sections:22if 'Club career' in s.title:23print(s.title)24for s in s.sections:25level = level + 126print(s.title)27if (s.sections is None):28return29else:30for s in s.sections:31level = level + 132print(s.title)33
34def execute(self):35self.get_club_details(self.wiki_page.sections, level=0)36
37
38# def print_sections(sections, level=0):
39# for s in sections:
40# if 'Club career' in s.title:
41# print(s.title)
42# #print("%s: %s - %s" % ("*" * (level + 1), s.title, s.text[0:100]))
43# for s in s.sections:
44# level=level + 1
45# print(s.title)
46# if(s.sections is None):
47# return
48# else:
49# for s in s.sections:
50# level = level+1
51# print(s.title)
52
53# break
54# print_sections(wiki_page.sections)
55
56
57def main():58player = input("Please Enter the player Info")59my_scraper_obj = myScraper(player)60my_scraper_obj.execute()61
62
63if __name__ == '__main__':64main()65