0

我想从玩家 Steam 个人资料中获取图像,并在我的网站上使用它们,所以当他们更改图像/照片时,它会在我身上发生变化。

这只是一次加载的一个,加载时会获取最新的 url。您可以使用此 url 进行测试,我需要的是使用此类在 div 中获取图像 url:并仅复制图像 url。

测试 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 . "'/>";          
    }
}
4

3 回答 3

3

使用 steam web api (文档),GetPlayerSummaries方法它可以在没有 html 报废的情况下工作

于 2013-01-06T16:49:37.193 回答
0

使用 koraktor 的蒸汽冷凝器,您可以轻松提取这些信息并使用它。

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);
于 2013-03-11T03:23:03.453 回答
-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

如果你想从同一个 url 中获取多张图片,然后替换preg_matchpreg_match_all并运行一个循环$profile_picture[1]

于 2013-01-06T16:58:26.317 回答