Skip to content

Commit dee1a91

Browse files
committed
Icc rankings scraper added
1 parent 78d8111 commit dee1a91

File tree

2 files changed

+107
-0
lines changed

2 files changed

+107
-0
lines changed

Icc_ranking_scraper/README.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# ICC rankings scraper
2+
3+
-Using this script you can get the ICC rankings of teams and players of different formats.
4+
5+
## Setup instructions
6+
7+
How to setup and run your script in user's system
8+
9+
"""
10+
Create an instance of `ICC` class.
11+
`python
12+
scraper = ICC()
13+
`
14+
| Method | Details |
15+
| ---------------------------- | ------------------------------------------------------------------- |
16+
| `.team_rankings(format)` | Returns the list of rankings of teams of desired format |
17+
|`.player_ranking(type,format)`| Returns the list of player ranking of desired type and format |
18+
"""
19+
20+
21+
## Detailed explanation of script, if needed
22+
23+
"""
24+
Create an instance of `ICC` class.\n
25+
Required Params - `format` - "ODI","T20" or "TEST"
26+
```python
27+
icc = ICC()
28+
icc.team_rankings(format="odi")
29+
```
30+
```js
31+
[
32+
{
33+
"rank":1,
34+
"team":"Australia"
35+
}
36+
]
37+
```
38+
"""
39+
40+
"""
41+
Create an instance of `ICC` class.\n
42+
Required Params - `format` - "ODI","T20" or "TEST"
43+
`type` - "batting","bowling" or "all-rounder"
44+
```python
45+
icc = ICC()
46+
icc.team_player(format="odi",type="batting")
47+
```
48+
```js
49+
[
50+
{
51+
"rank":1,
52+
"team":"Babar Azam"
53+
}
54+
]
55+
```
56+
"""
57+
58+
## Author(s)
59+
60+
[Arvind Srivastav](https://github.com/alwenpy)

Icc_ranking_scraper/rankings.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
from bs4 import BeautifulSoup
2+
import requests
3+
4+
5+
class ICC:
6+
7+
def __init__(self):
8+
self.url = "https://www.icc-cricket.com/rankings/mens/"
9+
10+
def team_rankings(self, format):
11+
12+
try:
13+
obj_keys = ["rank", "team"]
14+
resposne_list = []
15+
url = self.url + "team-rankings/" + format
16+
response = requests.get(url)
17+
soup = BeautifulSoup(response.content, "html.parser")
18+
teams = soup.find_all("span", class_="u-hide-phablet")
19+
for rank, team in enumerate(teams, 1):
20+
obj_values = [rank,team.get_text()]
21+
resposne_list.append(dict(zip(obj_keys, obj_values)))
22+
23+
24+
return resposne_list
25+
except:
26+
return None
27+
28+
def player_ranking(self, type, format):
29+
30+
try:
31+
url = self.url + f"/player-rankings/{format}/{type}"
32+
response = requests.get(url)
33+
soup = BeautifulSoup(response.content, "html.parser")
34+
top_player = soup.find(
35+
"div", class_="rankings-block__banner--name-large"
36+
).get_text()
37+
rest_players = soup.find_all(
38+
"td", class_="table-body__cell rankings-table__name name"
39+
)
40+
players_list = {}
41+
players_list[1] = top_player
42+
for rank, player in enumerate(rest_players, 2):
43+
players_list[rank] = player.get_text().replace("\n", "")
44+
45+
return players_list
46+
except:
47+
return None

0 commit comments

Comments
 (0)