-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathrankings.py
46 lines (37 loc) · 1.48 KB
/
rankings.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
from bs4 import BeautifulSoup
import requests
class ICC:
def __init__(self):
self.url = "https://www.icc-cricket.com/rankings/mens/"
def team_rankings(self, format):
try:
obj_keys = ["rank", "team"]
resposne_list = []
url = self.url + "team-rankings/" + format
response = requests.get(url)
soup = BeautifulSoup(response.content, "html.parser")
teams = soup.find_all("span", class_="u-hide-phablet")
for rank, team in enumerate(teams, 1):
obj_values = [rank, team.get_text()]
resposne_list.append(dict(zip(obj_keys, obj_values)))
return resposne_list
except:
return None
def player_ranking(self, type, format):
try:
url = self.url + f"/player-rankings/{format}/{type}"
response = requests.get(url)
soup = BeautifulSoup(response.content, "html.parser")
top_player = soup.find(
"div", class_="rankings-block__banner--name-large"
).get_text()
rest_players = soup.find_all(
"td", class_="table-body__cell rankings-table__name name"
)
players_list = {}
players_list[1] = top_player
for rank, player in enumerate(rest_players, 2):
players_list[rank] = player.get_text().replace("\n", "")
return players_list
except:
return None