Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function url_exists($url) {
- // Version 4.x supported
- $handle = curl_init($url);
- if (false === $handle)
- {
- return false;
- }
- curl_setopt($handle, CURLOPT_HEADER, false);
- curl_setopt($handle, CURLOPT_FAILONERROR, true); // this works
- curl_setopt($handle, CURLOPT_HTTPHEADER, Array("User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.15) Gecko/20080623 Firefox/2.0.0.15") ); // request as if Firefox
- curl_setopt($handle, CURLOPT_NOBODY, true);
- curl_setopt($handle, CURLOPT_RETURNTRANSFER, false);
- $connectable = curl_exec($handle);
- curl_close($handle);
- return $connectable;
- }
- function convertteam($team) {
- $ret = "ERROR";
- $ct = array('DAL' => 'DAL', 'NYG' => 'NYG', 'PHI' => 'PHI', 'WSH' => 'WAS', 'ARI' => 'ARI', 'SF' => 'SFO', 'SEA' => 'SEA', 'STL' => 'STL', 'CHI' => 'CHI', 'DET' => 'DET', 'GB' => 'GNB', 'MIN' => 'MIN', 'ATL' => 'ATL','CAR' => 'CAR','NO' => 'NOR', 'TB' => 'TAM', 'TEN' => 'TEN', 'JAC' => 'JAC', 'IND' => 'IND', 'HOU' => 'HOU', 'PIT' => 'PIT', 'CLE' => 'CLE', 'CIN' => 'CIN', 'BAL' => 'BAL', 'SD' => 'SDG', 'OAK' => 'OAK', 'KC' => 'KAN', 'DEN' => 'DEN','NYJ' => 'NYJ','NE' => 'NWE', 'MIA' => 'MIA','BUF' => 'BUF');
- $ret = $ct[$team];
- return $ret;
- }
- ini_set("memory_limit", "256M");
- set_time_limit(2400);
- include_once('simple_html_dom.php');
- $connection = mysql_connect("localhost",$USER,$PASSWORD);
- $sql = "SELECT * from Games.NFLGames where startDate > '2003-08-20' and startDate < '2009-05-05'";
- $query = mysql_query($sql, $connection);
- while ($row = mysql_fetch_array($query, MYSQL_ASSOC)) {
- $url = "http://scores.espn.go.com/nfl/boxscore?gameId=" . $row['idNFL'];
- If (url_exists($url) == TRUE) {
- $dom = file_get_html($url);
- If(sizeof($dom->find('div[class="line-score-container]')) > 0) {
- $awayteam_scores = $dom->find('div[class="line-score-container]', 0)->find('table[class="linescore"]', 0)->find('tr', 1);
- $hometeam_scores = $dom->find('div[class="line-score-container]', 0)->find('table[class="linescore"]', 0)->find('tr', 2);
- $away_score['Team'] = convertteam(trim($awayteam_scores->find('td', 0)->plaintext));
- $away_score['1Q'] = trim($awayteam_scores->find('td', 1)->plaintext);
- $away_score['2Q'] = trim($awayteam_scores->find('td', 2)->plaintext);
- $away_score['3Q'] = trim($awayteam_scores->find('td', 3)->plaintext);
- $away_score['4Q'] = trim($awayteam_scores->find('td', 4)->plaintext);
- $home_score['Team'] = convertteam(trim($hometeam_scores->find('td', 0)->plaintext));
- $home_score['1Q'] = trim($hometeam_scores->find('td', 1)->plaintext);
- $home_score['2Q'] = trim($hometeam_scores->find('td', 2)->plaintext);
- $home_score['3Q'] = trim($hometeam_scores->find('td', 3)->plaintext);
- $home_score['4Q'] = trim($hometeam_scores->find('td', 4)->plaintext);
- If (sizeof($awayteam_scores->find('td')) == 7) {
- $away_score['OT'] = trim($awayteam_scores->find('td', 5)->plaintext);
- $away_score['TOT'] = trim($awayteam_scores->find('td', 6)->plaintext);
- $home_score['OT'] = trim($hometeam_scores->find('td', 5)->plaintext);
- $home_score['TOT'] = trim($hometeam_scores->find('td', 6)->plaintext);
- } else {
- $away_score['OT'] = "X";
- $away_score['TOT'] = trim($awayteam_scores->find('td', 5)->plaintext);
- $home_score['OT'] = "X";
- $home_score['TOT'] = trim($hometeam_scores->find('td', 5)->plaintext);
- }
- $SQL = "INSERT INTO `Results`.`NFLScores` (`idNFL`, `startDate`, `homeTeam`, `awayTeam`, `home_1Q`, `home_2Q`, `home_3Q`, `home_4Q`, `home_OT`, `home_TOT`, `away_1Q`, `away_2Q`, `away_3Q`, `away_4Q`, `away_OT`, `away_TOT`) VALUES ('" . $row['idNFL'] . "', '" . $row['startDate'] . "', '" . $row['homeTeam'] . "', '" . $row['awayTeam'] . "', '" . $home_score['1Q'] . "', '" . $home_score['2Q'] . "', '" . $home_score['3Q'] . "', '" . $home_score['4Q'] . "', '" . $home_score['OT'] . "', '" . $home_score['TOT'] . "', '" . $away_score['1Q'] . "', '" . $away_score['2Q'] . "', '" . $away_score['3Q'] . "', '" . $away_score['4Q'] . "', '" . $away_score['OT'] . "', '" . $away_score['TOT'] . "');";
- //echo $SQL . "<BR>";
- mysql_query($SQL, $connection);
- }
- if(sizeof($dom->find('div[class="story-container"]', 0)->find('div[class="mod-container mod-open mod-open-gamepack"]')) > 0) {
- $teamstats = $dom->find('div[class="story-container"]', 0)->find('div[class="mod-container mod-open mod-open-gamepack"]', 1)->find('table[class="mod-data"]', 0);
- $home_boxscore['1D'] = $teamstats->find('tr',1)->find('td', 1)->plaintext;
- //$home_boxscore['P1D'] = $teamstats->find('tr',2)->find('td', 1)->plaintext;
- //$home_boxscore['R1D'] = $teamstats->find('tr',3)->find('td', 1)->plaintext;
- //$home_boxscore['1DPen'] = $teamstats->find('tr',4)->find('td', 1)->plaintext;
- $home_3DETemp = $teamstats->find('tr',2)->find('td', 1)->plaintext;
- $home_3DETemp = explode("-", $home_3DETemp);
- $home_boxscore['3DE_S'] = $home_3DETemp[0];
- $home_boxscore['3DE_A'] = $home_3DETemp[1];
- $home_4DETemp = $teamstats->find('tr',3)->find('td', 1)->plaintext;
- $home_4DETemp = explode("-", $home_4DETemp);
- $home_boxscore['4DE_S'] = $home_4DETemp[0];
- $home_boxscore['4DE_A'] = $home_4DETemp[1];
- //$home_boxscore['TP'] = $teamstats->find('tr',7)->find('td', 1)->plaintext;
- $home_boxscore['TY'] = $teamstats->find('tr',4)->find('td', 1)->plaintext;
- $home_boxscore['Pass'] = $teamstats->find('tr',5)->find('td', 1)->plaintext;
- $home_PC = $teamstats->find('tr',6)->find('td', 1)->plaintext;
- $home_PC = explode("-", $home_PC);
- $home_boxscore['PASS_C'] = $home_PC[0];
- $home_boxscore['PASS_A'] = $home_PC[1];
- $home_boxscore['YPP'] = $teamstats->find('tr',7)->find('td', 1)->plaintext;
- $home_boxscore['Rush'] = $teamstats->find('tr',8)->find('td', 1)->plaintext;
- $home_boxscore['RushAtt'] = $teamstats->find('tr',9)->find('td', 1)->plaintext;
- $home_boxscore['YPR'] = $teamstats->find('tr',10)->find('td', 1)->plaintext;
- //$home_RZ = $teamstats->find('tr',15)->find('td', 1)->plaintext;
- //$home_RZ = explode("-", $home_RZ);
- //$home_boxscore['RZ_C'] = $home_RZ[0];
- //$home_boxscore['RZ_A'] = $home_RZ[1];
- $home_PEN = $teamstats->find('tr',11)->find('td', 1)->plaintext;
- $home_PEN = explode("-", $home_PEN);
- $home_boxscore['PEN_N'] = $home_PEN[0];
- $home_boxscore['PEN_YDS'] = $home_PEN[1];
- $home_boxscore['Turnovers'] = $teamstats->find('tr',12)->find('td', 1)->plaintext;
- $home_boxscore['FumblesLost'] = $teamstats->find('tr',13)->find('td', 1)->plaintext;
- $home_boxscore['IntThrown'] = $teamstats->find('tr',14)->find('td', 1)->plaintext;
- //$home_boxscore['DefSTTD'] = $teamstats->find('tr',20)->find('td', 1)->plaintext;
- $home_boxscore['Possession'] = $teamstats->find('tr',15)->find('td', 1)->plaintext;
- $away_boxscore['1D'] = $teamstats->find('tr',1)->find('td', 2)->plaintext;
- //$away_boxscore['P1D'] = $teamstats->find('tr',2)->find('td', 2)->plaintext;
- //$away_boxscore['R1D'] = $teamstats->find('tr',3)->find('td', 2)->plaintext;
- //$away_boxscore['1DPen'] = $teamstats->find('tr',4)->find('td', 2)->plaintext;
- $away_3DETemp = $teamstats->find('tr',2)->find('td', 2)->plaintext;
- $away_3DETemp = explode("-", $away_3DETemp);
- $away_boxscore['3DE_S'] = $away_3DETemp[0];
- $away_boxscore['3DE_A'] = $away_3DETemp[1];
- $away_4DETemp = $teamstats->find('tr',3)->find('td', 2)->plaintext;
- $away_4DETemp = explode("-", $away_4DETemp);
- $away_boxscore['4DE_S'] = $away_4DETemp[0];
- $away_boxscore['4DE_A'] = $away_4DETemp[1];
- //$away_boxscore['TP'] = $teamstats->find('tr',7)->find('td', 2)->plaintext;
- $away_boxscore['TY'] = $teamstats->find('tr',4)->find('td', 2)->plaintext;
- $away_boxscore['Pass'] = $teamstats->find('tr',5)->find('td', 2)->plaintext;
- $away_PC = $teamstats->find('tr',6)->find('td', 2)->plaintext;
- $away_PC = explode("-", $away_PC);
- $away_boxscore['PASS_C'] = $away_PC[0];
- $away_boxscore['PASS_A'] = $away_PC[1];
- $away_boxscore['YPP'] = $teamstats->find('tr',7)->find('td', 2)->plaintext;
- $away_boxscore['Rush'] = $teamstats->find('tr',8)->find('td', 2)->plaintext;
- $away_boxscore['RushAtt'] = $teamstats->find('tr',9)->find('td', 2)->plaintext;
- $away_boxscore['YPR'] = $teamstats->find('tr',10)->find('td', 2)->plaintext;
- //$away_RZ = $teamstats->find('tr',15)->find('td', 2)->plaintext;
- //$away_RZ = explode("-", $away_RZ);
- //$away_boxscore['RZ_C'] = $away_RZ[0];
- //$away_boxscore['RZ_A'] = $away_RZ[1];
- $away_PEN = $teamstats->find('tr',11)->find('td', 2)->plaintext;
- $away_PEN = explode("-", $away_PEN);
- $away_boxscore['PEN_N'] = $away_PEN[0];
- $away_boxscore['PEN_YDS'] = $away_PEN[1];
- $away_boxscore['Turnovers'] = $teamstats->find('tr',12)->find('td', 2)->plaintext;
- $away_boxscore['FumblesLost'] = $teamstats->find('tr',13)->find('td', 2)->plaintext;
- $away_boxscore['IntThrown'] = $teamstats->find('tr',14)->find('td', 2)->plaintext;
- //$away_boxscore['DefSTTD'] = $teamstats->find('tr',20)->find('td', 2)->plaintext;
- $away_boxscore['Possession'] = $teamstats->find('tr',15)->find('td', 2)->plaintext;
- $SQL = "INSERT INTO `Results`.`NFLBoxscore` (`idNFL`, `startDate`, `team`, `HomeAway`, `FirstDowns`, `Efficiency3D_S`, `Efficiency3D_A`, `Efficiency4D_S`, `Efficiency4D_A`, `TotalYards`, `Passing`, `Passing_Comp`, `Passing_Att`, `YardsPerPass`, `Rushing`, `Rushing_Att`, `YardsPerRush`, `Penalties_Number`, `Penalties_Yards`, `Turnovers`, `FumblesLost`, `InterceptionsThrown`, `Possession`) VALUES ('" . $row['idNFL'] . "', '" . $row['startDate'] . "', '" . $row['awayTeam'] . "', 'A', '" . $away_boxscore['1D'] . "', '" . $away_boxscore['3DE_S'] . "', '" . $away_boxscore['3DE_A'] . "', '" . $away_boxscore['4DE_S'] . "', '" . $away_boxscore['4DE_A'] . "', '" . $away_boxscore['TY'] . "', '" . $away_boxscore['Pass'] . "', '" . $away_boxscore['PASS_C'] . "', '" . $away_boxscore['PASS_A'] . "', '" . $away_boxscore['YPP'] . "', '" . $away_boxscore['Rush'] . "', '" . $away_boxscore['RushAtt'] . "', '" . $away_boxscore['YPR'] . "', '" . $away_boxscore['PEN_N'] . "', '" . $away_boxscore['PEN_YDS'] . "', '" . $away_boxscore['Turnovers'] . "', '" . $away_boxscore['FumblesLost'] . "', '" . $away_boxscore['IntThrown'] . "', '" . $away_boxscore['Possession'] . "');";
- //echo $SQL . "<BR>";
- mysql_query($SQL, $connection);
- $SQL = "INSERT INTO `Results`.`NFLBoxscore` (`idNFL`, `startDate`, `team`, `HomeAway`, `FirstDowns`, `Efficiency3D_S`, `Efficiency3D_A`, `Efficiency4D_S`, `Efficiency4D_A`, `TotalYards`, `Passing`, `Passing_Comp`, `Passing_Att`, `YardsPerPass`, `Rushing`, `Rushing_Att`, `YardsPerRush`, `Penalties_Number`, `Penalties_Yards`, `Turnovers`, `FumblesLost`, `InterceptionsThrown`, `Possession`) VALUES ('" . $row['idNFL'] . "', '" . $row['startDate'] . "', '" . $row['awayTeam'] . "', 'A', '" . $home_boxscore['1D'] . "', '" . $home_boxscore['3DE_S'] . "', '" . $home_boxscore['3DE_A'] . "', '" . $home_boxscore['4DE_S'] . "', '" . $home_boxscore['4DE_A'] . "', '" . $home_boxscore['TY'] . "', '" . $home_boxscore['Pass'] . "', '" . $home_boxscore['PASS_C'] . "', '" . $home_boxscore['PASS_A'] . "', '" . $home_boxscore['YPP'] . "', '" . $home_boxscore['Rush'] . "', '" . $home_boxscore['RushAtt'] . "', '" . $home_boxscore['YPR'] . "', '" . $home_boxscore['PEN_N'] . "', '" . $home_boxscore['PEN_YDS'] . "', '" . $home_boxscore['Turnovers'] . "', '" . $home_boxscore['FumblesLost'] . "', '" . $home_boxscore['IntThrown'] . "', '" . $home_boxscore['Possession'] . "');";
- mysql_query($SQL, $connection);
- }
- $dom->clear();
- unset($dom);
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment