Skip to content

Instantly share code, notes, and snippets.

@B3none
Created October 3, 2018 20:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save B3none/1336cbf3cb8d3c6696ce15f0d143e7b6 to your computer and use it in GitHub Desktop.
Save B3none/1336cbf3cb8d3c6696ce15f0d143e7b6 to your computer and use it in GitHub Desktop.
Basic script which allows us to scrape the avatar and name of a steam profile
<?php
function getProfile($steamId) {
$contents = file_get_contents('https://steamcommunity.com/profiles/' . $steamId);
$dom = new DOMDocument();
libxml_use_internal_errors(true);
$dom->loadHTML($contents);
libxml_clear_errors();
$xpath = new \DOMXPath($dom);
$steamDetails = [];
// TODO: Re-write the XPath queries.
foreach ($xpath->query('/html/body/div[1]/div[7]/div[3]/div[1]/div[1]/div/div/div/div[1]/div[1]/span[1]') as $name) {
$steamDetails['name'] = $name->nodeValue;
break;
}
foreach ($xpath->query('/html/body/div[1]/div[7]/div[3]/div[1]/div[1]/div/div/div/div[2]/div/img/@src') as $avatarSource) {
$steamDetails['avatarSource'] = $avatarSource->value;
break;
}
echo json_encode($steamDetails);
}
getProfile('76561198028510846');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment