AFL Tables Scraper

The AFL Tables Scraper is a Python package and command-line executable that downloads Australian Football League (AFL) match data from the fantastic database AFL Tables, and outputs it in a structured, machine-readable form.

Full documentation available on Github Pages

Installation

Note that this module requires python 3.5 and above

Install using:

pip install afl_tables

Python Usage

The AFL Tables module can be used to scrape matches as follows:

from afl_tables import MatchScraper

# Make a scraper for a particular year (2015)
rounds = MatchScraper.scrape(2015)

See the docs on Round for more information on how to use this object

CLI Usage

The AFL Tables module also creates a command-line script called afltables, which can be used to scrape data outside of a python script. Usage is as follows

usage: Scrapes the AFL Tables website and returns JSON data representing the matches
   [-h] year

positional arguments:
  year        The year to scrape

optional arguments:
  -h, --help  show this help message and exit

Changelog

0.0.2

  • Fix for missing fields in the attendees/date/venue part of the table, for example in 2020

  • Added some tests for the package

0.0.1

  • Initial release

API Documentation

class afl_tables.Match(teams: List[afl_tables.TeamMatch], winner: str, attendees: int = None, date: <module 'datetime' from '/usr/lib/python3.7/datetime.py'> = None, venue: str = None, bye: bool = False)[source]

Represents a single match of AFL

Variables
  • teams – A list of teams, with either two teams or one team (a bye)

  • attendees – Number of attendees at this match

  • date – The time and date that this match started

  • venue – The name of the venue at which this match was played

  • winner – The name of the winning team

classmethod parse(table: bs4.element.Tag)[source]

Parses a Match from the appropriate <table> element

class afl_tables.MatchScraper[source]

A static class that can be used to scrape the matches from the AFL Tables website

classmethod scrape(year: int) → List[afl_tables.Round][source]

Scrapes all the match data for the given year

Parameters

year – The year to scrape, e.g. 2015

class afl_tables.Round(title: str, matches: list = [])[source]

Represents a single round of AFL, with one or more matches being played in that round

Variables
  • title – The human-readable title for this round

  • matches – A list of matches played during this round

classmethod parse(title: bs4.element.Tag, table: bs4.element.Tag)afl_tables.Round[source]

Parses a round from two table elements that define it

Parameters
  • title – The <table> tag that contains this round’s header

  • table – The <table> tag that contains this round’s data

class afl_tables.Score(goals, behinds)[source]

Represents an AFL score for a single team at a given point in time

Variables
  • goals – Number of goals scored

  • behinds – Number of behinds/points scored

classmethod parse(pointstring: str)afl_tables.Score[source]

Parses a string in the form x.y

property score

The calculated score as a single integer

Development

To build the documentation, first install the dev dependencies, then run Sphinx:

pip install -r dev-dependencies.txt
sphinx-build -b html docs /some/path

Indices and tables