Here are step-by-step instructions on how to download the GitHub repo and run the main.py script on your Mac:
- Open Terminal (you can find it by searching in Spotlight).
- Type the following command to check if you have Git installed:
git --version
- If it’s not installed, your Mac will prompt you to install the command line developer tools. Just follow the on-screen instructions.
- In Terminal, navigate to the directory where you want to store the project (use the
cdcommand). - Run the following command to download the repository:
git clone https://github.com/andrewjosephallen/espnapiscraper
- After it’s cloned, navigate into the project folder:
cd espnapiscraper
- Install the
espn_apipackage used in themain.pyscript. You’ll also need to installcsv, but it’s part of Python's standard library, so no additional installation is required. - Run the following command to install
espn_api:pip install espn-api
-
Now, run the
main.pyscript by typing:python main.py
-
The script will prompt you for input:
- League ID: Input the ID of your fantasy league.
- Year: Input the year of the league season.
- ESPN S2: Paste your
espn_s2cookie value. - SWID: Paste your
swidcookie value.
-
After providing these values, the script will generate a CSV file with weekly scores and free agents, saving it in the current directory.
This process should set up the repository and run the main.py script smoothly on your Mac!
To access data from private ESPN Fantasy Football leagues, you'll need to provide authentication cookies (espn_s2 and SWID). Follow these steps to retrieve them from your browser.
- Visit ESPN Fantasy Football.
- Log in with your ESPN account credentials.
- Right-click anywhere on the page and select Inspect.
- In the Developer Tools window, click on the Application tab.
- In the left sidebar under Storage, expand Cookies and select
https://fantasy.espn.com.
- Right-click anywhere on the page and select Inspect.
- Click on the Storage tab.
- In the left sidebar, expand Cookies and select
https://fantasy.espn.com.
-
In the list of cookies, find
espn_s2andSWID.- espn_s2: A long alphanumeric string.
- SWID: A string formatted as
{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}(including the curly braces).
- Double-click on the value for
espn_s2to highlight it, then right-click and select Copy. - Repeat the process for
SWID.
Now you have the espn_s2 and SWID cookies, which you can use in your code to authenticate and access private ESPN Fantasy Football league data.