从steam id获取steam游戏
Get steam games from steam id
我正在尝试创建一个 python 程序来获取 steam id 和 return 特定用户在他的库中拥有的游戏。我在网上搜索,没有找到 python。
你能帮帮我吗?
我找到了这个 Steam 开发者网站,你可以用它来实现 python。
https://developer.valvesoftware.com/wiki/SteamID
Steam ID as a Steam Community ID
A Steam ID can be converted to Steam Community ID for use on the Steam Community website.
Let X, Y and Z constants be defined by the SteamID: STEAM_X:Y:Z
.
There are 2 methods of conversion:
For 32-bit systems
Using the formula W=Z*2+Y
, a SteamID can be converted to the following link:
http or https://steamcommunity.com/path/[letter:1:W]
The account type letter can be found in the table above. The path can be found in the same place after the slash symbol.
Example: http://steamcommunity.com/gid/[g:1:4]
For 64-bit systems:
Let V be SteamID64 identifier of the account type (can be found in the table above in hexadecimal format).
Using the formula W=Z*2+V+Y
, a SteamID can be converted to the following link:
http or https://steamcommunity.com/path/W
As for the 32-bit method, the path can be found in the table above, again after the slash.
Example: http://steamcommunity.com/profiles/76561197960287930
试试这个(我用完全 error_handling 为你写了一个 Class,你可以用 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)
祝你好运...:)
我正在尝试创建一个 python 程序来获取 steam id 和 return 特定用户在他的库中拥有的游戏。我在网上搜索,没有找到 python。
你能帮帮我吗?
我找到了这个 Steam 开发者网站,你可以用它来实现 python。
https://developer.valvesoftware.com/wiki/SteamID
Steam ID as a Steam Community ID
A Steam ID can be converted to Steam Community ID for use on the Steam Community website. Let X, Y and Z constants be defined by the SteamID:
STEAM_X:Y:Z
. There are 2 methods of conversion:For 32-bit systems
Using the formula
W=Z*2+Y
, a SteamID can be converted to the following link: http or https://steamcommunity.com/path/[letter:1:W] The account type letter can be found in the table above. The path can be found in the same place after the slash symbol. Example: http://steamcommunity.com/gid/[g:1:4]For 64-bit systems:
Let V be SteamID64 identifier of the account type (can be found in the table above in hexadecimal format). Using the formula
W=Z*2+V+Y
, a SteamID can be converted to the following link: http or https://steamcommunity.com/path/W As for the 32-bit method, the path can be found in the table above, again after the slash. Example: http://steamcommunity.com/profiles/76561197960287930
试试这个(我用完全 error_handling 为你写了一个 Class,你可以用 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)
祝你好运...:)