Git Product home page Git Product logo

laliga-data's Introduction

laliga-data

Scraping data from spanish football La Liga website.

LaLiga Logo

This is a tool entirely written in Python that allows to scrap all player data available in the official website of the spanish football league for the current season. At the time of writing, three competitions are available: female first division, male first division and male second division.

Setup

Create a Python virtualenv and install requirements:

$ python3.10 -m venv venv
$ source venv/bin/activate
$ pip install -r requirements.txt

Optionally, you can create a .env file in the working directory to overwrite settings from settings.py.

Other requirements

There are few external requirements for the project to work properly:

Usage

$ python main.py --help
Usage: main.py [OPTIONS]

Options:
  -v, --verbose              Loglevel increased to debug.
  -n, --num_players INTEGER  Num players (per competition) to be scraped. If
                             0, all available players will be retrieved.
                             [default: 0]
  --help                     Show this message and exit.

A common usage would be just python main.py -v. It takes aproximately 2 hours to finish execution (depending on the network issues).

Once finished, a csv file will be present in repo containing all scraped data from players.

Data

  • Generated datasets are stored in the datasets folder and updated weekly.
  • Files will have a name like S2122-laliga-players.csv depending on the football season.
  • A description of the columns can be found in col-specs.csv.
  • Datasets are also available at Kaggle.

laliga-data's People

Contributors

sdelquin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

jorge4514

laliga-data's Issues

Error al lanzar script

Hola Sergio. Estoy intentando utilizar el script de python para scrapear las estadísticas de la liga. Una vez configurado todo sin error, cuando lanzo el script, al cabo de un rato, me devuelve este error:

221121 18:43:19 [INFO ] Moving to https://www.laliga.com/en-ES/advanced-stats (core.py:43) 221121 18:43:55 [ERROR ] TimeoutException by Selenium (network.py:60) 221121 18:43:55 [WARNING ] No advertisements found (core.py:73) 221121 18:43:55 [INFO ] Getting season (core.py:76) Traceback (most recent call last) ────────────────────────────────╮ │ /laliga-data/main.py:27 in run │ │ │ │ 24 │ logger.setLevel(logzero.DEBUG if verbose else logzero.INFO) │ │ 25 │ │ │ 26 │ scraper = LaLigaScraper() │ │ ❱ 27 │ scraper.get_player_data(num_players) │ │ 28 │ scraper.to_dataframe() │ │ 29 │ scraper.wrangle_dataframe() │ │ 30 │ scraper.to_csv() │ │ │ │ ╭──────────────────────────── locals ─────────────────────────────╮ │ │ │ num_players = 0 │ │ │ │ scraper = <laliga.core.LaLigaScraper object at 0x117fad0d0> │ │ │ │ verbose = False │ │ │ ╰─────────────────────────────────────────────────────────────────╯ │ │ │ │ /laliga-data/laliga/core.py:152 in get_player_data │ │ │ │ 149 │ │ │ │ logger.error('Unable to retrieve data') │ │ 150 │ │ │ 151 │ def get_player_data(self, num_players=0): │ │ ❱ 152 │ │ while competition := self._load_next_competition(): │ │ 153 │ │ │ time.sleep(10) │ │ 154 │ │ │ self.get_player_data_by_competition(competition, num_players) │ │ 155 │ │ │ │ ╭──────────────────────────── locals ─────────────────────────────╮ │ │ │ num_players = 0 │ │ │ │ self = <laliga.core.LaLigaScraper object at 0x117fad0d0> │ │ │ ╰─────────────────────────────────────────────────────────────────╯ │ │ │ │ /laliga-data/laliga/core.py:119 in _load_next_competition │ │ │ │ 116 │ │ │ │ yield build_url(tr.td.a['href']) │ │ 117 │ │ │ 118 │ def _load_next_competition(self): │ │ ❱ 119 │ │ competitions_div = self.webdriver.find_element_by_xpath(self.competitions_div_xp │ │ 120 │ │ self.webdriver.execute_script('window.scrollTo(0, 0);') │ │ 121 │ │ time.sleep(1) │ │ 122 │ │ competitions_div.click() │ │ │ │ ╭───────────────────────── locals ─────────────────────────╮ │ │ │ self = <laliga.core.LaLigaScraper object at 0x117fad0d0> │ │ │ ╰──────────────────────────────────────────────────────────╯ │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────╯ AttributeError: 'WebDriver' object has no attribute 'find_element_by_xpath'

¿Sabes a qué puede ser debido?

un saludo y gracias.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.