Amazing-Python-Scripts

Форк
0
64 строки · 1.8 Кб
1
import pandas as pd
2
import requests
3
import urllib.request
4
from bs4 import BeautifulSoup
5
import wikipediaapi
6

7

8
class myScraper:
9

10
    # Initializing the Constructor
11
    def __init__(self, player):
12

13
        self.wiki_lang = wikipediaapi.Wikipedia(
14
            '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)
24
            for s in s.sections:
25
                level = level + 1
26
                print(s.title)
27
                if (s.sections is None):
28
                    return
29
                else:
30
                    for s in s.sections:
31
                        level = level + 1
32
                        print(s.title)
33

34
    def execute(self):
35
        self.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

57
def main():
58
    player = input("Please Enter the player Info")
59
    my_scraper_obj = myScraper(player)
60
    my_scraper_obj.execute()
61

62

63
if __name__ == '__main__':
64
    main()
65

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.