StrikeEngine

Videos – Parts – Information – Directory – Insurance

FPL Statistics Download. How-To Get FPL Stats in Excel/CSV

Thumbnail of FPL stats download guide

If you want to download the FPL statistics, this guide will walk you through the process. These will be latest FPL stats for the current season and will come from the Premier League Fantasy Football website. No knowledge necessary!

This fantastic post showed me how to do it but a few things have changed since the post was written so here is what I did to get it to work as of today.


FPL Stats Download Procedure API

1.Copy and past the code below into Notepad and save the file as “pull.php”. You don’t need to understand any of this code.

<!DOCTYPE html>
<html>
<head>

<style>
#player_info {
    font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
    border-collapse: collapse;
    width: 100%;
}

#player_info td, #player_info th {
    border: 1px solid #ddd;
    padding: 8px;
}

#player_info tr:nth-child(even){background-color: #f2f2f2;}

#player_info tr:hover {background-color: #ddd;}

#player_info th {
    padding-top: 12px;
    padding-bottom: 12px;
    text-align: left;
    background-color: #242424;
    color: white;
}
</style>
</head>
<body>
<button onclick="doCSV()"">Export HTML Table To CSV File</button>
<script>function doCSV() {
    var table = document.getElementById("player_info").innerHTML;
    var data = table.replace(/<thead>/g, '')
        .replace(/<\/thead>/g, '')
        .replace(/<tbody>/g, '')
        .replace(/<\/tbody>/g, '')
        .replace(/<tr>/g, '')
        .replace(/<\/tr>/g, '\r\n')
        .replace(/<th>/g, '')
        .replace(/<\/th>/g, ',')
        .replace(/<td>/g, '')
        .replace(/<\/td>/g, ',')
        .replace(/\t/g, '')
        .replace(/\n/g, '');
    var mylink = document.createElement('a');
    mylink.download = "fplinfo.csv";
    mylink.href = "data:application/csv," + escape(data);
    mylink.click();
}</script>
<?php
$json=file_get_contents("https://fantasy.premierleague.com/api/bootstrap-static/");
//suggested to use http://docs.guzzlephp.org/en/stable/ instead of file_get_contents

$data =  json_decode($json, true);
?>
<table id ="player_info">
<tr>
    <th>ID</th>
    <th>Web Name</th>
    <th>Player ID</th>
    <th>Full Name</th>
    <th>Team</th>
    <th>News</th>
    <th>Position</th>
    <th>Current Price</th>
    <th>Value Season</th>
    <th>Cost Change from Start</th>
    <th>Percentage selected by</th>
    <th>Transfers In</th>
    <th>Transfers Out</th>
    <th>Total Points</th>
    <th>Points Per Game</th>
    <th>Minutes</th>
    <th>Goals Scored</th>
    <th>Assists</th>
    <th>Clean Sheets</th>
    <th>Goals Conceded</th>
    <th>Own Goals</th>
    <th>Penalties Saved</th>
    <th>Penalties Missed</th>
    <th>Yellow Cards</th>
    <th>Red Cards</th>
    <th>Saves</th>
    <th>Bonus Points</th>
    <th>Bonus Point System Score</th>
    <th>Influence</th>
    <th>Creativity</th>
    <th>Threat</th>    
    <th>ICT Index</th>
    <th>EA Index</th>
</tr>

<?PHP
foreach($data['elements'] as $key=>$item)
{
    ?>
    <tr>
        <td><?PHP echo $item['id']; ?></td>
        <td><?PHP echo $item['web_name']; ?></td>
        <td><?PHP echo $item['code']; ?></td>
        <td><?PHP echo $item['first_name']; ?> <?PHP echo $item['second_name']; ?></td>
        <td><?PHP echo $item['team_code']; ?></td>
        <td><?PHP echo $item['news']; ?></td>
        <td><?PHP echo $item['element_type']; ?></td>
        <td><?PHP echo $item['now_cost']; ?></td>
        <td><?PHP echo $item['value_season']; ?></td>
        <td><?PHP echo $item['cost_change_start']; ?></td>
        <td><?PHP echo $item['selected_by_percent']; ?></td>
        <td><?PHP echo $item['transfers_in']; ?></td>
        <td><?PHP echo $item['transfers_out']; ?></td>
        <td><?PHP echo $item['total_points']; ?></td>
        <td><?PHP echo $item['points_per_game']; ?></td>
        <td><?PHP echo $item['minutes']; ?></td>
        <td><?PHP echo $item['goals_scored']; ?></td>
        <td><?PHP echo $item['assists']; ?></td>
        <td><?PHP echo $item['clean_sheets']; ?></td>
        <td><?PHP echo $item['goals_conceded']; ?></td>
        <td><?PHP echo $item['own_goals']; ?></td>
        <td><?PHP echo $item['penalties_saved']; ?></td>
        <td><?PHP echo $item['penalties_missed']; ?></td>
        <td><?PHP echo $item['yellow_cards']; ?></td>
        <td><?PHP echo $item['red_cards']; ?></td>
        <td><?PHP echo $item['saves']; ?></td>
        <td><?PHP echo $item['bonus']; ?></td>
        <td><?PHP echo $item['bps']; ?></td>
        <td><?PHP echo $item['influence']; ?></td>
        <td><?PHP echo $item['creativity']; ?></td>
        <td><?PHP echo $item['threat']; ?></td>
        <td><?PHP echo $item['ict_index']; ?></td>
        <td><?PHP echo $item['ea_index']; ?></td>
    </tr>
    <?PHP
}
?>
</table>


2.Download xampp and install it. Basically xampp lets your computer work like a webserver.

You can read read the post I linked to above for more information in xampp if you are unfamiliar, but you don’t need to know anything for this process. (The video in that linked post is super informative).

3.Move pull.php into the htdocs folder in the xampp directory (located where you created it/where you downloaded it)

4.Open xampp Control Panel and start Apache

5.Type http://localhost/pull.php in the address bar of your browser and click the export/download button (at the top left of the page)

and bingo you are done!

The file you downloaded will contain the latest FPL statistics as shown the the Fantasy Premier League website. You can read the stats and manipulate them in Excel/LIbre Office etc. If you’re familiar with php you can add your own code the pull.php file and make it do whatever calculations you want automatically, that way you download the results of your formulas automatically (so you don’t have to repeat the process every-time in excel). Or if it’s easier, just do the formulas in excel to get the FPL stats you need to do your analysis.

If you have any questions of comment, leave them below!

Find performance parts on ebay




This page was last modified Apr 18, 2023 @ 12:32 pm

StrikeEngine TV Highlights

Comments:

Your email address will not be published. Required fields are marked *

4 × five =

Get our news in your inbox - Subscribe

* indicates required