Skip to main content

A Python script to scrape football data from FBRef

Project description

FBRef Stats

A python script to scrape football data from FBRef

Check out the documentation

Static Badge Static Badge

About

FBRef Stats is a Python script which uses BeautifulSoup and requests to scrape data from FBRef. This is a small side project I work on in my free time. As an avid soccer fan and someone who finds sports stats interesting, I tried making a program which takes player stats into account so I could gain an advantage on my fantasy leagues with my friends. However, I could not find many good free libraries which provided soccer data, so I resolved to build one myself.

Installation

To install this project, input the following into the command line:

pip install fbrefstats

From there, you can import the package into your program using:

from fbrefstats import LeagueScraper, GeneralScraper, StatStrings

Usage

As seen above, there are three classes within the fbrefstats script: (The names of these classes may change in the future, they are currently placeholders)

  • LeagueScraper
    • Contains scraping methods relating to leagues. An object is needed to access these methods, with each object representing a specific league.
  • GeneralScraper
    • Contains scraping methods that are independant. They are static and do not tie into any specific league.
  • StatStrings
    • Class full of variables holding strings, which are used when calling the method LeagueScraper.getLeagueLeaders()

Check out the documentation for info on how to use the script.

Other libraries used

As of now, the libraries used within this project are:

  • BeautifulSoup4
  • requests
  • pandas
  • StringIO
  • fake-http-reader | Link to the repo here

To-do

As of right now, this script is still in a very early development phase, and I am only working on it as a personal side project. I have a few things I am thinking of adding:

  • Update README.md (Urgent)

  • Add a documentation file

  • Update the documentation file

  • Static functions
    Split the Scraper class into two classes: LeagueScraper and GeneralScraper, which contains static methods

  • Randomized requests headers to avoid detectability when scraping

  • Different table formats
    I've learnt that pandas dataframes already have built-in functions for this: pandas.DataFrame.to_csv() and pandas.DataFrame.to_string()

  • Upload FBRefStats to PyPI ☑\

  • More scraping!
    There is so much data available on FBRef, so I would love to add more methods so that this data can be accessed through the script

  • Add support for different league formats
    As of right now, there are very few leagues supported as I am yet to add functionality to leagues with different formats (promotion/relegation playoffs, MLS post-season, or Apertura/Clausura formats commonly found in Latin America)

  • Add nationality argument to GeneralScraper.getPlayerLink()
    Currently, GeneralScraper.getPlayerLink() takes one argument: inputted_player_name. The method returns a list of URLs depending on which players were found when searching with inputted_player_name. This can get annoying when there are many players with similar names, so adding a nationality argument would be useful for searching.

License

GNU GPL

Project details


Download files

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

Source Distribution

fbrefstats-0.1.11.tar.gz (20.0 kB view details)

Uploaded Source

Built Distribution

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

fbrefstats-0.1.11-py3-none-any.whl (20.6 kB view details)

Uploaded Python 3

File details

Details for the file fbrefstats-0.1.11.tar.gz.

File metadata

  • Download URL: fbrefstats-0.1.11.tar.gz
  • Upload date:
  • Size: 20.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.13.0

File hashes

Hashes for fbrefstats-0.1.11.tar.gz
Algorithm Hash digest
SHA256 701f79270642fe26d0d4e35f379fdb2a209b4bfa8a3aab9ca5689426316ad37e
MD5 c2c475f503fe3361fe057c2b36eb60a5
BLAKE2b-256 314a8625ec8ee82b16bff946b0f98d5bd1b689658474b0bb00d66c1d2f086176

See more details on using hashes here.

File details

Details for the file fbrefstats-0.1.11-py3-none-any.whl.

File metadata

  • Download URL: fbrefstats-0.1.11-py3-none-any.whl
  • Upload date:
  • Size: 20.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.13.0

File hashes

Hashes for fbrefstats-0.1.11-py3-none-any.whl
Algorithm Hash digest
SHA256 37c6d6d2710dfe35ea09600f63e81853eafc885bcfeb2061844c0583651101d7
MD5 dfeb07eb916bd34fbcc4a16d4ac90d53
BLAKE2b-256 344d0cf4aa6c174e976a70e6e6b60bc13a0a509fb96321e4bf523775ddda658a

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