DEV Community

Bugrahan Saka
Bugrahan Saka

Posted on Fully Autonomous

Transfermarkt Scraper in Python: Every Squad, Contract and Market Value in a League

Transfermarkt is where football's squad data lives: every club in every league, every player with position, age, nationality, contract end and Transfermarkt's own market value, plus the fee each club paid to sign him. Clubs, agents, journalists and fantasy players all read it. For scouting lists, contract-expiry tracking or market value research, it is a clean dataset. Here is how to pull a whole league into Python.

Why one script on one server isn't enough

Transfermarkt pages are plain server-rendered HTML, so a few requests.get calls from your laptop come back fine. The trouble starts when you crawl: every squad of every league, every season, from a server. That traffic gets throttled and the IP blocked. Sending each request through Scrape.do puts it on a rotating IP. A plain request is enough, no extra parameters: 1 credit per page.

import csv
import re
import requests

TOKEN = "<your_token>"
BASE = "https://www.transfermarkt.com"


def fetch(url):
    r = requests.get("https://api.scrape.do/", params={"token": TOKEN, "url": url}, timeout=90)
    r.raise_for_status()
    return r.text


def text(fragment):
    return re.sub(r"\s+", " ", re.sub(r"<[^>]+>", " ", fragment)).strip()


def euros(value):
    m = re.search(r"([\d.]+)(bn|m|k)", value.replace("B", "bn").lower())
    return round(float(m.group(1)) * {"bn": 1e9, "m": 1e6, "k": 1e3}[m.group(2)]) if m else None


def rows(html):
    body = html.split('<table class="items">')[1].split("<tbody>")[1].split("</tbody>")[0]
    return re.split(r'<tr class="(?:odd|even)">', body)[1:]
Enter fullscreen mode Exit fullscreen mode

One detail saves a lot of URL building: Transfermarkt ignores the slug in its URLs. /manchester-city/kader/verein/281 and /-/kader/verein/281 are the same page, so only the numeric IDs matter.

Step 1: every club in a league

A competition page (/-/startseite/wettbewerb/GB1 for the Premier League, ES1 LaLiga, L1 Bundesliga, IT1 Serie A, FR1 Ligue 1, TR1 Süper Lig) has a table.items with one row per club: crest, name, squad size, average age, foreigners, average and total market value.

def clubs(code):
    html = fetch(f"{BASE}/-/startseite/wettbewerb/{code}")
    for row in rows(html):
        link = re.search(r'<td class="hauptlink[^"]*"><a title="([^"]+)" href="[^"]*/verein/(\d+)', row)
        cells = [text(c) for c in re.findall(r"<td[^>]*>(.*?)</td>", row, re.S)]
        yield {"id": link.group(2), "club": link.group(1), "squad": cells[2], "avg_age": cells[3],
               "total_value": cells[6]}
Enter fullscreen mode Exit fullscreen mode

The table footer holds the league total. For the 2026/27 Premier League it reads €14.11bn.

Step 2: every player in a squad

Add /plus/1 to a squad URL and Transfermarkt switches to the detailed view: shirt number, date of birth and age, nationalities, height, foot, joined date, previous club, contract end and market value. Two fields hide in attributes:

  1. The transfer fee is in the previous club's link title: "Paris Saint-Germain: Ablöse €30.00M".
  2. Nationalities are flag images; read their title, there can be two.
def squad(club_id, club):
    html = fetch(f"{BASE}/-/kader/verein/{club_id}/plus/1")
    for row in rows(html):
        player = re.search(r'<td class="hauptlink">\s*<a href="[^"]*/spieler/(\d+)"[^>]*>(.*?)</a>', row, re.S)
        position = re.findall(r"<tr>\s*<td>(.*?)</td>\s*</tr>", row.split("</table>")[0], re.S)
        cells = re.findall(r'<td class="(?:zentriert|rechts)[^"]*">(.*?)</td>', row.split("</table>", 1)[1], re.S)
        fee = re.search(r'title="[^"]*: Ablöse ([^"]+)"', cells[5])
        yield {
            "club": club,
            "player": text(player.group(2)),
            "position": text(position[-1]) if position else "",
            "born": text(cells[0]),
            "nationality": ", ".join(re.findall(r'title="([^"]+)" alt="[^"]*" class="flaggenrahmen"', cells[1])),
            "foot": text(cells[3]),
            "joined": text(cells[4]),
            "fee": fee.group(1) if fee else "",
            "contract": text(cells[6]),
            "market_value": text(cells[7]),
            "value_eur": euros(text(cells[7])),
        }
Enter fullscreen mode Exit fullscreen mode

Each row nests a small table (photo, name, position), so split the row at its first </table> before reading the cells after it.

Step 3: the whole league to CSV

players = []
for c in clubs("GB1"):
    players += list(squad(c["id"], c["club"]))

with open("premier_league.csv", "w", newline="", encoding="utf-8") as fh:
    writer = csv.DictWriter(fh, fieldnames=players[0].keys())
    writer.writeheader()
    writer.writerows(players)
print(len(players), "players")
Enter fullscreen mode Exit fullscreen mode

A live run returned 548 players from the 20 Premier League clubs for 21 credits: one page for the league, one per squad. Their market values add up to €14.11bn, the same total Transfermarkt prints under the league table. The median player is valued at €20m. 101 players have a contract that ends on 30 June 2027, worth €1.02bn between them, and 93 players are 21 or younger, worth €2.48bn. The squads hold 63 nationalities.

Limits to know

  • Market values are estimates. Transfermarkt's community and editors set them; they are not fees paid. The fee column is the fee for the player's last move.
  • Seasons: add /saison_id/2025 to read 25/26 squads and values. Leave it out for the current season.
  • Missing values: youth players can have no market value, no contract date or no shirt number. Treat - as empty.

Skip the code

The same scraper is an open-source package with a CLI:

pip install transfermarkt-scraper
export SCRAPEDO_TOKEN=<your_token>
transfermarkt-scraper clubs GB1 -f csv -o clubs.csv
transfermarkt-scraper league GB1 -f csv -o premier_league.csv
transfermarkt-scraper player 418560
Enter fullscreen mode Exit fullscreen mode

Source and tests: github.com/bugrahansss/transfermarkt-scraper

Use the data responsibly

Transfermarkt's numbers are the work of its editors and community: respect its terms, keep request rates reasonable, don't republish player photos, and credit Transfermarkt when you publish analysis built on them. Players are people, so use birth dates and birthplaces only where you need them.

Run it at scale with Scrape.do

Every page is one plain Scrape.do call: no proxy pool, no retries to babysit. A whole league costs about as many credits as it has clubs. Get 1000 free credits and start scraping with Scrape.do.

Top comments (0)