Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.