Skip to content

Instantly share code, notes, and snippets.

@donaldsteele
Last active October 30, 2019 02:16
Show Gist options
  • Save donaldsteele/117bfaa69da0aaedd1095d39db9b55db to your computer and use it in GitHub Desktop.
Save donaldsteele/117bfaa69da0aaedd1095d39db9b55db to your computer and use it in GitHub Desktop.
Extract the scores from the live cyber patriot scoreboard into csv format
<?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