Last active
October 30, 2019 02:16
-
-
Save donaldsteele/117bfaa69da0aaedd1095d39db9b55db to your computer and use it in GitHub Desktop.
Extract the scores from the live cyber patriot scoreboard into csv format
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$url = "http://scoreboard.uscyberpatriot.org/"; | |
$ch = curl_init(); | |
$timeout = 5; | |
curl_setopt($ch, CURLOPT_URL, $url); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); | |
$html = curl_exec($ch); | |
curl_close($ch); | |
# Create a DOM parser object | |
$dom = new DOMDocument(); | |
@$dom->loadHTML($html); | |
$xpath = new DOMXPath( $dom); | |
$rows= $xpath->query('//table/tr'); | |
foreach( $rows as $row) { | |
$cols = $xpath->query( 'td', $row); // Get the <td> elements that are children of this <tr> | |
$colCount=count($cols); | |
for ($x = 0; $x < $colCount; $x++) { | |
echo $cols[$x]->textContent; | |
if ($x == ($colCount - 1)) { | |
echo "\n"; | |
} else { | |
echo ','; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment