代码之家  ›  专栏  ›  技术社区  ›  erez

从steam id获取steam游戏[关闭]

  •  -3
  • erez  · 技术社区  · 7 年前

    我正在尝试创建一个python程序,该程序获取steam id并返回特定用户在其库中拥有的游戏。我在网上搜索,没有找到python。
    你能帮我吗?

    2 回复  |  直到 7 年前
        1
  •  1
  •   DRPK    7 年前

    试试这个(我为您编写了一个具有完全错误处理的类,您可以更高效地编写此代码…使用BeautifulSoup或其他软件包(不适用于私人用户!):

    import requests, json
    
    
    class SteamGameGrabber(object):
    
        def __init__(self):
    
            self.url = ''
            self.headers = {
                'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36'}
            self.start_tag = "var rgGames"
            self.end_tag = "var rgChangingGames"
    
            self.last_data = {}
    
        def send_request(self):
    
            try:
                response = requests.get(self.url, headers=self.headers)
                raw_data = str(response.content, encoding="utf-8")
            except:
                return [False, "Something Wrong! Connection Lost!"]
    
            else:
                if response.status_code == 200:
                    return [True, raw_data]
                else:
                    return [False, "Check Your Connection ( status_code is Not 200 )!"]
    
        def pars_data(self, get_input):
    
            def find_between(s, first, last):
    
                try:
                    start = s.index(first) + len(first)
                    end = s.index(last, start)
                except:
                    return [False, "Parsing Error"]
                else:
                    return [True, s[start:end]]
    
            if "<title>Steam Community :: Error</title>" in get_input:
                return [False, "I Can Not Find This ID on Steam Server"]
    
            if '<div class="profile_private_info">' in get_input:
                return [False, "This profile is private, I can not Decode it, sorry."]
    
            get_data = find_between(get_input, self.start_tag, self.end_tag)
    
            if get_data[0] is True:
    
                dict_data = json.loads(get_data[1].strip().lstrip("=").rstrip(";").strip())
    
                try:
                    for box in dict_data:
    
                        game_id = str(box['appid']).strip()
                        game_name = box['name'].strip()
    
                        if game_name in self.last_data:
                            pass
    
                        else:
    
                            self.last_data[game_name] = game_id
                except:
                    return [False, "Format is Wrong"]
    
                else:
                    return [True, self.last_data]
    
            else:
                return [False, get_data[1]]
    
        def call_all(self, get_id):
    
            if get_id.strip() == "":
                return "Please Insert Your Steam ID"
    
            else:
    
                self.url = 'http://steamcommunity.com/id/{0}/games/?tab=all'.format(get_id)
    
                get_state_1 = self.send_request()
    
                if get_state_1[0] is True:
    
                    get_state_2 = self.pars_data(get_state_1[1])
                    return get_state_2[1]
    
                else:
                    return get_state_1[1]
    
    
    
    # Call This Class Now:
    
    your_id = 'erfan1'
    
    make_object = SteamGameGrabber()
    get_result = make_object.call_all(your_id)
    
    if isinstance(get_result, dict):
    
        print("Dict Format : ", get_result, "\n")
        print("Target ID : ", my_id, "\n")
    
        for names, appid in get_result.items():
            print(names, appid)
    
    else:
        print(get_result)
    

    祝你好运……:)

        2
  •  0
  •   Rita Alamino    7 年前

    我为steam找到了这个开发人员网站,您可以将其与python实现结合使用。

    https://developer.valvesoftware.com/wiki/SteamID

    Steam ID作为Steam社区ID

    Steam ID可以转换为Steam社区ID,以便在Steam社区网站上使用。 设X、Y和Z常数由蒸汽ID定义: STEAM_X:Y:Z . 有两种转换方法:

    对于32位系统

    W=Z*2+Y ,可以将SteamID转换为以下链接: http或 https://steamcommunity.com/path/[letter:1:W] 账户类型信函见上表。路径可以在斜线符号后的同一位置找到。 例子: http://steamcommunity.com/gid/[g:1:4]

    对于64位系统:

    假设V是帐户类型的SteamID64标识符(可以在上表中以十六进制格式找到)。 使用公式 W=Z*2+V+Y ,可以将SteamID转换为以下链接: http或 https://steamcommunity.com/path/W 对于32位方法,路径可以在上表中找到,同样在斜杠之后。 例子: http://steamcommunity.com/profiles/76561197960287930