scraping fanteam.com with python (Bearer token)

Viewed 155

I am trying to scrape the fantasy points achieved from individual players on fanteam.com. For example of this tournament: https://www.fanteam.com/fantasy/dashboard/439470/8955379/3 I would like to know which player achieved how many points. Since it is tedious to click through all teams until you found all players, I am working on a python script. By network analysis, I found that the data are on https://fanteam-game.api.scoutgg.net/fantasy_teams/8955379?round=3 (maybe there are even better sources):

Values to scrape

Unfortunately, you need a bearer token to access this link. I tried different manuals from the internet, but nothing worked so far. How do I obtain the token?

1 Answers

Try:

import json
import requests

url = "https://fanteam-game.api.scoutgg.net/fantasy_teams/8955379?round=3"
headers = {"Authorization": "Bearer fanteam undefined"}

data = requests.get(url, headers=headers).json()

# uncomment this to print all data:
# print(json.dumps(data, indent=4))

for p in data["playerChoices"]:
    print(
        p["realPlayer"]["firstName"], p["realPlayer"]["lastName"], p["points"]
    )

Prints:

Matteo Berrettini 56.78
Hubert Hurkacz 58.28
Felix Auger-Aliassime 50.13
Ashleigh Barty 52.3
Karolina Muchova 54.25
Barbora Krejcikova 30.3
Related