我想从玩家蒸汽配置文件中获取图片,并在我的网站上使用它们,所以当他们更改图片/照片时,它会改变我。
这只是一次加载的一个,加载时它将获得最新的URL。 您可以使用此网址进行测试,我需要的是使用此类获取div中的图像网址:并仅复制图像网址。
链接到测试steamprofile:http://steamcommunity.com/profiles/76561197991341238
我尝试过的代码:
foreach($html->find('div[class=avatarFull]') as $div)
{
foreach($div->find('img') as $img)
{
echo "<img src='" . $img->src . "'/>";
}
}
答案 0 :(得分:3)
使用steam web api, GetPlayerSummaries 方法无需HTML报废即可使用
答案 1 :(得分:0)
使用koraktor的Steam Condenser,您可以轻松获取此信息并使用它。
require_once('steam/db.php');
$_STEAMAPI = "YOURAPIKEYHERE"; // You get this from http://steamcommunity.com/dev/apikey
$playersStr = ""; // This is a comma separated list of profile IDs
// if you don't have those, Steam Condenser has functions to acquire it
$players = array(); // For this example, I'm building an array of players assuming you'll have multiple players returned.
// You are free to skip this if you are only pulling one back
$url = "http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=$_STEAMAPI&steamids=$playersStr";
$json_object= file_get_contents($url);
$json_decoded = json_decode($json_object);
foreach ($json_decoded->response->players as $player)
{
$players[$player->steamid]['personaname'] = $player->personaname; // In game name
$players[$player->steamid]['profileurl'] = $player->profileurl; // URL to their Steam Community Page
$players[$player->steamid]['avatar'] = $player->avatar; // Small Avatar Icon URL
$players[$player->steamid]['avatarmedium'] = $player->avatarmedium; // Thumbnail avatar URL
$players[$player->steamid]['avatarfull'] = $player->avatarfull; // Full sized Avatar URL
}
如果您没有玩家的个人资料ID但拥有Steam ID,则可以获得如下个人资料ID:
$profile_id = SteamId::convertSteamIdToCommunityId($steam_id);
答案 2 :(得分:-2)
我认为 RegEx (preg_match
)是更简单的方法
$html = file_get_contents("http://steamcommunity.com/profiles/76561197991341238");
preg_match('/<div class="avatarFull"><img src="(.*)" \/><\/div>/i', $html, $profile_picture); // $profile_picture[1]; is the url itself
如果您尝试从同一网址抓取多张图片,请将preg_match
替换为preg_match_all
并在$profile_picture[1]
上运行循环