Skip to main content

Scraping data package for www.understat.com

Project description

License: MIT Python: 3.9 PyPI Selenium: 4.0

underdata

Python package for get data of www.understat.com. There are available 6 european leagues: Premier League, La Liga, Bundesliga, Serie A, Ligue 1 and Russian Premier League from season 2014/2015.


Note

This package is in development yet, then can change.


Installation

To install the package:

git clone git@github.com:osvaldomx/UnderData.git
cp ~/understat /<your_project>

This package use selenium therefore you will have to install geckodriver.

Getting started

Object url
underdata.League() https://www.understat.com/league/<league_name>/<year>
underdata.Team() https://www.understat.com/team/<team_name>/<year>
underdata.Player() https://www.understat.com/player/<player_id>
underdata.Match() https://www.understat.com/player/<match_id>

Examples

League

To get general information of a league:

# import
>>> from underdata.League import League
>>> league = League(league="epl", year="2018")
>>> league.get_info()
'Get info of EPL'

this will open a browser with geckodriver with the purpose of get general information of the league EPL in the year 2018. To access to the information, run:

>>> league.seasons                  # Get seasons availables in www.understats.com
['2021', '2020', '2019', '2018', '2017', '2016', '2015', '2014']

>>> league.table                    # Get the current qualification table or correspondant to the specific year
     N                     Team   M   W   D   L   G  GA  PTS          xG          xGA         xPTS
0    1          Manchester City  38  32   2   4  95  23   98  93.72-1.28   25.73+2.73   90.64-7.36
1    2                Liverpool  38  30   7   1  89  22   97  79.46-9.54   29.15+7.15  83.45-13.55
.
.
.

>>> league.table_goals              # Get top-10 of scorers
    N                     Player             Team  Apps   Min   G   A          xG          xA  xG90  xA90
0   1  Pierre-Emerick Aubameyang          Arsenal    36  2740  22   5  23.55+1.55   4.99-0.01  0.77  0.16
1   2                 Sadio Mané        Liverpool    36  3100  22   1  16.76-5.24   5.12+4.12  0.49  0.15
.
.
.

Team

To get general information of a league:

# import
>>> from underdata.Team import Team
>>> team = Team(team="liverpool", year="2018")
>>> Team.get_info()
'Get info of Liverpool'

this will open a browser with geckodriver with the purpose of get general information of the team Liverpool in the year 2018. To access to the information, run:

>>> team.games                      # Get info of games of team in specific year
    week          date                     home                     away  goals_home  goals_away  xG_home  xG_away result                               url
0      1  Aug 12, 2018                liverpool                 West Ham           4           0     4.34     0.40    win  https://understat.com/match/9205
1      2  Aug 20, 2018           Crystal Palace                liverpool           0           2     0.37     2.82    win  https://understat.com/match/9216
.
.
.

>>> team.player_stats              # Get info of all team players in specific year
      Id                   Player  Pos  Apps   Min   G   A  Sh90  KP90          xG          xA  xG90  xA90
0    838               Sadio Mané  F M    36  3100  22   1  2.53  1.31  16.76-5.24   5.12+4.12  0.49  0.15
1   1250            Mohamed Salah    F    38  3274  22   8  3.77  1.87  21.79-0.21  10.47+2.47  0.60  0.29
.
.
.

Player

To get general information of a player:

# import
>>> from underdata.Player import Player
>>> player = Player(player_id="1250")
>>> player.get_info()
'Get info of Mohamed Salah'

this will open a browser with geckodriver with the purpose of get general information of the player with id 1250. To access to the information, run:

>>> player.table_seasons                    # Get info of seasons of the player
      Season        Team  Apps   Min   G   A  Sh90  KP90          xG          xA  xG90  xA90
0  2021/2022   Liverpool     9   810  10   5  4.44  2.33   7.50-2.50   3.14-1.86  0.83  0.35
1  2020/2021   Liverpool    37  3085  22   5  3.68  1.60  20.25-1.75   6.53+1.53  0.59  0.19
.
.
.

>>> player.player_history                   # Get info of all appears of the player
           Date               Home Score             Away  Pos Min Sh  G KP  A         xG         xA
0    2021-10-24  Manchester United   0-5        Liverpool  FWR  90  7  3  2  1  2.25-0.75  0.51-0.49
1    2021-10-16            Watford   0-5        Liverpool  FWR  90  5  1  2  1  0.40-0.60  0.36-0.64
.
.
.

Match

To get general information of a Match:

# import
>>> from underdata.Match import Match
>>> match = Match(match_id="16463")
>>> match.get_info()
'Get info of Manchester United vs Liverpool'

this will open a browser with geckodriver with the purpose of get general information of the match with id 16463. To access to the information, run:

>>> match.match_stats                    # Get stats of the match
                     Player  Pos  Min  Sh  G  KP  A         xG         xA
0              David de Gea   GK   90   0  0   0  0       0.00       0.00
1         Aaron Wan-Bissaka   DR   90   0  0   0  0       0.00       0.00
2           Victor Lindelöf   DC   90   0  0   0  0       0.00       0.00
...
25               Sadio Mané  Sub    8   1  0   0  0  0.11+0.11       0.00
26  Alex Oxlade-Chamberlain  Sub   21   1  0   1  0  0.02+0.02  0.04+0.04
27             Curtis Jones  Sub   64   1  0   1  0  0.15+0.15  0.03+0.03

Contributing

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

underdata-0.1.2-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

Details for the file underdata-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: underdata-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 9.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.5

File hashes

Hashes for underdata-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e176695d106dc899cbd9b7627abf292337189b174dd91270586ffd2ab21dee32
MD5 a2e441d123c91f862baacb7804266574
BLAKE2b-256 bcf0bec8709917aba68adb194f20dbb03e0ed26779a2f6f21e1db0dd03f31655

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page