我如何抓取一段文字并将其放在我的网站上?

时间:2014-06-16 17:26:53

标签: html json steam steam-web-api

我正在尝试从Steam获取网页的URL。我正在使用它来获取访问它的任何用户的图片的URL。 以下是当我询问用户信息时Steam给我的代码:

{
"response": {
    "players": [
        {
            "steamid": "76561xxxxxxxxx",
            "communityvisibilitystate": 3,
            "profilestate": 1,
            "personaname": "xxxxx",
            "lastlogoff": 1402722290,
            "profileurl": "http://steamcommunity.com/id/xxxxxxxxxx/",
            "avatar": "http://media.steampowered.com/steamcommunity/public/images/avatars/f1/f1dd6xxxxxxxxxx883caxxxxxe6abaxxxxxxx32d4.jpg",
            "avatarmedium": "http://media.steampowered.com/steamcommunity/public/images/avatars/f1/fxxxxxxxxxxx83caf82xxxfexxxxxxxxxxaf1732d4_medium.jpg",
            "avatarfull": "http://media.steampowered.com/steamcommunity/public/images/avatars/f1/f1dxxxxxxxx88883caf82xxxxfccfexxxxxxxxx732d4_full.jpg",
            "personastate": 0,
            "realname": "xxxxx Walker",
            "primaryclanid": "103582xx142952xxxx",
            "timecreated": 1063407589,
            "personastateflags": 0,
            "loccountrycode": "US",
            "locstatecode": "WA",
            "loccityid": 3961
        }
    ]

}

我想要的是"avatar":的网址,但我对此有点新鲜。

获取网址后,我希望将其放在<div>上,并附上其他信息,例如姓名等。现在非常感谢帮助!

1 个答案:

答案 0 :(得分:0)

假设你正在使用javascript:

var s = GetSteamInfo(); //s is the string which represents the string
var o = JSON.parse(s);
var player = o["response"]["players"][0];

//now, to get the data
var avatar = player["avatar"];
var steamid = player["steamid"];
//etc..