Created
October 3, 2018 20:56
-
-
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
This file contains hidden or 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 | |
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