Skip to content

Commit

Permalink
Fork of code from ScraperWiki at https://classic.scraperwiki.com/scra…
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewmuir1980 committed Aug 9, 2015
0 parents commit 64ddb51
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
@@ -0,0 +1,2 @@
# Ignore output of scraper
data.sqlite
1 change: 1 addition & 0 deletions README.textile
@@ -0,0 +1 @@
Scrapes fantasy football data from the official premier league website. Each record shows the stats for each player for each week.
75 changes: 75 additions & 0 deletions scraper.php
@@ -0,0 +1,75 @@
<?php
require 'scraperwiki/simple_html_dom.php';

// get base url
$url = 'http://fantasy.premierleague.com/web/api/elements/';

//should create automatic method to find range of pages
#$lastplayer=

//set range of players to look through - currently there are 675
$players=range(1,675);
#$players=range(1,$lastplayer);

//need to add specific numbers such as Jan transfers to array

//scrape page for each player
foreach($players as $player)
{
$html = scraperwiki::scrape($url.$player);

// load html into dom
$dom = new simple_html_dom();
$dom->load($html);

//turn dom into a string
$json = $dom;

//make the json string an array which i confusingly call an object
$obj = json_decode($json);

//Test:
#print_r($obj);

//get the fixture history for the player
foreach($obj->fixture_history->all as $rows)
{

//create results table
$results = array(
'index' => strval($player.$rows[1]),
'first_name' => strval($obj->first_name),
'last_name' => strval($obj->web_name),
'position' => strval($obj->type_name),
'team_name' => strval($obj->team_name),
'date' => strval($rows[0]),
'week' => strval($rows[1]),
'result' => strval($rows[2]),
'minutes_played' => strval($rows[3]),
'goals_scored'=>strval($rows[4]),
'assists'=>strval($rows[5]),
'clean_sheets'=>strval($rows[6]),
'goals_conceded'=>strval($rows[7]),
'own_goals'=>strval($rows[8]),
'penalties_saved'=>strval($rows[9]),
'penalties missed'=>strval($rows[10]),
'yellow_cards'=>strval($rows[11]),
'red_cards'=>strval($rows[12]),
'saves'=>strval($rows[13]),
'bonus'=>strval($rows[14]),
'EA_Spots_PPI'=>strval($rows[15]),
'net_transfers'=>strval($rows[16]),
'value'=>strval($rows[17]),
'points'=>strval($rows[18]),

);

//check results
#print_r($results);

//save
scraperwiki::save(array('index'),$results);
}

}
?>

0 comments on commit 64ddb51

Please sign in to comment.