Skip to content

Instantly share code, notes, and snippets.

@achudars
Last active December 17, 2015 03:29
Show Gist options
  • Save achudars/5543886 to your computer and use it in GitHub Desktop.
Save achudars/5543886 to your computer and use it in GitHub Desktop.
A Web Scraper in PHP to get points, completed courses and attended events from Microsoft Virtual Academy (MVA). It depends on SIMPLE HTML DOM PARSER. Also you need to make sure that in PHP settings allow_url_fopen and allow_url_include flags are set to ON, and you must have these extensions selected: php_openssl and php_curl .
<!--
Use this code as you please!
The most important bit is passing the $id as a string.
As long as you know the id, you can get the info you need.
Note: It is quite slow (at least for me)!
As there are more than a million people in Microsoft Virtual Academy,
you could pass a random id in that range and see what you get! =)
-->
<!DOCTYPE html>
<html>
<head>
<title>Title</title>
</head>
<body>
<?php
// include the PHP DOM library
include('simple_html_dom.php');
// test ids
$id1 = "249021"; // Aleksandrs Cudars
$id2 = "22837"; // Paul Bird
$id3 = "324950"; // Peter Smith has only 'courses'
$id4 = "861260"; // no name has only 'attended events'
$id5 = "1148427"; // Peter Burgess (at the moment has 3 courses and 3 events. easy to count, easy to test)
// get the contents e.g., id = 249021
function getPoints($id) {
$url = "https://www.microsoftvirtualacademy.com/Profile.aspx?alias=" . $id;
$html = file_get_html($url);
echo '<h3>ID: ' . $id . '</h3>';
echo 'Points: ' . $html->getElementById("microsite-points-value");
getCompletedCourses($html);
getAttendedEvents($html);
}
function getCompletedCourses($html) {
$courses = 0;
foreach($html->find('div[class=approved-study-points]') as $course) {
$courses++;
}
echo "\nCourses completed: " . $courses;
}
function getAttendedEvents($html) {
$events = 0;
foreach($html->find('div[class=microsite-community-item]') as $event) {
$events++;
}
echo "\nEvents attended: " . $events;
}
getPoints($id1);
getPoints($id2);
getPoints($id3);
getPoints($id4);
getPoints($id5);
?>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment