mirror of
https://github.com/SocksPls/hltv-api
synced 2025-04-30 23:43:08 +00:00
Working again. Fixed errors due to changed hltv layout and encoding errors in python 3.7
This commit is contained in:
parent
162a1d42a4
commit
aa58cd672c
2 changed files with 23 additions and 23 deletions
|
@ -27,7 +27,7 @@ Provides an API for HLTV
|
||||||
## `get_players`
|
## `get_players`
|
||||||
|
|
||||||
```python
|
```python
|
||||||
>>> hltv.get_players("6667")
|
>>> hltv.get_players("6665")
|
||||||
['karrigan', 'olofmeister', 'GuardiaN', 'NiKo', 'rain']
|
['karrigan', 'olofmeister', 'GuardiaN', 'NiKo', 'rain']
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
36
main.py
36
main.py
|
@ -31,15 +31,15 @@ def top30teams():
|
||||||
teams = page.find("div", {"class": "ranking"})
|
teams = page.find("div", {"class": "ranking"})
|
||||||
teamlist = []
|
teamlist = []
|
||||||
for team in teams.find_all("div", {"class": "ranked-team standard-box"}):
|
for team in teams.find_all("div", {"class": "ranked-team standard-box"}):
|
||||||
newteam = {'name': team.find('div', {"class": "header"}).select('.name')[0].text.strip(),
|
newteam = {'name': team.find('div', {"class": "ranking-header"}).select('.name')[0].text.strip(),
|
||||||
'rank': converters.to_int(team.select('.position')[0].text.strip(), regexp=True),
|
'rank': converters.to_int(team.select('.position')[0].text.strip(), regexp=True),
|
||||||
'rank-points': converters.to_int(team.find('span', {'class': 'points'}).text, regexp=True),
|
'rank-points': converters.to_int(team.find('span', {'class': 'points'}).text, regexp=True),
|
||||||
'team-id': converters.to_int(team.select('.name')[0]["data-url"].split("/")[2], regexp=True),
|
'team-id': converters.to_int(team.find('a', {'class': 'details moreLink'})['href'].split('/')[-1]),
|
||||||
'team-players': []}
|
'team-players': []}
|
||||||
for player_div in team.find_all("td", {"class": "player-holder"}):
|
for player_div in team.find_all("td", {"class": "player-holder"}):
|
||||||
player = {}
|
player = {}
|
||||||
player['name'] = player_div.find('img', {'class': 'playerPicture'})['title']
|
player['name'] = player_div.find('img', {'class': 'playerPicture'})['title']
|
||||||
player['player-id'] = converters.to_int(player_div.find('span', {"class": "js-link"})['data-url'].split("/")[2])
|
player['player-id'] = converters.to_int(player_div.select('.pointer')[0]['href'].split("/")[-2])
|
||||||
newteam['team-players'].append(player)
|
newteam['team-players'].append(player)
|
||||||
teamlist.append(newteam)
|
teamlist.append(newteam)
|
||||||
return teamlist
|
return teamlist
|
||||||
|
@ -51,8 +51,8 @@ def top_players():
|
||||||
playersArray = []
|
playersArray = []
|
||||||
for player in players.find_all("div", {"class": "top-x-box standard-box"}):
|
for player in players.find_all("div", {"class": "top-x-box standard-box"}):
|
||||||
playerObj = {}
|
playerObj = {}
|
||||||
playerObj['country'] = player.find('img', {'class': 'flag country gtSmartphone-only'})['alt'].encode('utf8')
|
playerObj['country'] = player.find_all('img')[1]['alt'].encode('utf8')
|
||||||
buildName = player.find('img', {'class': 'img'})['alt'].encode('utf8').split('\'')
|
buildName = player.find('img', {'class': 'img'})['alt'].split("'")
|
||||||
playerObj['name'] = buildName[0].rstrip() + buildName[2]
|
playerObj['name'] = buildName[0].rstrip() + buildName[2]
|
||||||
playerObj['nickname'] = player.find('a', {'class': 'name'}).text.encode('utf8')
|
playerObj['nickname'] = player.find('a', {'class': 'name'}).text.encode('utf8')
|
||||||
playerObj['rating'] = player.find('div', {'class': 'rating'}).find('span', {'class': 'bold'}).text.encode('utf8')
|
playerObj['rating'] = player.find('div', {'class': 'rating'}).find('span', {'class': 'bold'}).text.encode('utf8')
|
||||||
|
@ -63,12 +63,12 @@ def top_players():
|
||||||
|
|
||||||
|
|
||||||
def get_players(teamid):
|
def get_players(teamid):
|
||||||
page = get_parsed_page("http://www.hltv.org/?pageid=362&teamid=" + teamid)
|
page = get_parsed_page("http://www.hltv.org/?pageid=362&teamid=" + str(teamid))
|
||||||
titlebox = page.find("div", {"class": "teamProfile"})
|
titlebox = page.find("div", {"class": "bodyshot-team"})
|
||||||
players = []
|
players = []
|
||||||
for player in titlebox.find_all("div", {"class": "bodyshot-team"}):
|
for player_link in titlebox.find_all("a"):
|
||||||
players = player.text.strip().encode('utf8').split('\n\n\n\n')
|
players.append(player_link['title'])
|
||||||
players = [x.strip(' ') for x in players]
|
|
||||||
return players
|
return players
|
||||||
|
|
||||||
|
|
||||||
|
@ -114,11 +114,11 @@ def _get_current_lineup(player_anchors):
|
||||||
players = []
|
players = []
|
||||||
for player_anchor in player_anchors[0:5]:
|
for player_anchor in player_anchors[0:5]:
|
||||||
player = {}
|
player = {}
|
||||||
buildName = player_anchor.find("img", {"class": "container-width"})["alt"].encode('utf8').split('\'')
|
buildName = player_anchor.find("img", {"class": "container-width"})["alt"].split('\'')
|
||||||
player['country'] = player_anchor.find("div", {"class": "teammate-info standard-box"}).find("img", {"class": "flag"})["alt"].encode('utf8')
|
player['country'] = player_anchor.find("div", {"class": "teammate-info standard-box"}).find("img", {"class": "flag"})["alt"]
|
||||||
player['name'] = buildName[0].rstrip() + buildName[2]
|
player['name'] = buildName[0].rstrip() + buildName[2]
|
||||||
player['nickname'] = player_anchor.find("div", {"class": "teammate-info standard-box"}).find("div", {"class": "text-ellipsis"}).text.encode('utf8')
|
player['nickname'] = player_anchor.find("div", {"class": "teammate-info standard-box"}).find("div", {"class": "text-ellipsis"}).text
|
||||||
player['maps-played'] = int(re.search(r'\d+', player_anchor.find("div", {"class": "teammate-info standard-box"}).find("span").text.encode('utf8')).group())
|
player['maps-played'] = int(re.search(r'\d+', player_anchor.find("div", {"class": "teammate-info standard-box"}).find("span").text).group())
|
||||||
players.append(player)
|
players.append(player)
|
||||||
return players
|
return players
|
||||||
|
|
||||||
|
@ -130,11 +130,11 @@ def _get_historical_lineup(player_anchors):
|
||||||
players = []
|
players = []
|
||||||
for player_anchor in player_anchors[5::]:
|
for player_anchor in player_anchors[5::]:
|
||||||
player = {}
|
player = {}
|
||||||
buildName = player_anchor.find("img", {"class": "container-width"})["alt"].encode('utf8').split('\'')
|
buildName = player_anchor.find("img", {"class": "container-width"})["alt"].split('\'')
|
||||||
player['country'] = player_anchor.find("div", {"class": "teammate-info standard-box"}).find("img", {"class": "flag"})["alt"].encode('utf8')
|
player['country'] = player_anchor.find("div", {"class": "teammate-info standard-box"}).find("img", {"class": "flag"})["alt"].encode('utf8')
|
||||||
player['name'] = buildName[0].rstrip() + buildName[2]
|
player['name'] = buildName[0].rstrip() + buildName[2]
|
||||||
player['nickname'] = player_anchor.find("div", {"class": "teammate-info standard-box"}).find("div", {"class": "text-ellipsis"}).text.encode('utf8')
|
player['nickname'] = player_anchor.find("div", {"class": "teammate-info standard-box"}).find("div", {"class": "text-ellipsis"}).text.encode('utf8')
|
||||||
player['maps-played'] = int(re.search(r'\d+', player_anchor.find("div", {"class": "teammate-info standard-box"}).find("span").text.encode('utf8')).group())
|
player['maps-played'] = int(re.search(r'\d+', player_anchor.find("div", {"class": "teammate-info standard-box"}).find("span").text).group())
|
||||||
players.append(player)
|
players.append(player)
|
||||||
return players
|
return players
|
||||||
|
|
||||||
|
@ -269,10 +269,10 @@ if __name__ == "__main__":
|
||||||
pp.pprint(top_players())
|
pp.pprint(top_players())
|
||||||
|
|
||||||
pp.pprint('get_players')
|
pp.pprint('get_players')
|
||||||
pp.pprint(get_players('6137'))
|
pp.pprint(get_players('6665'))
|
||||||
|
|
||||||
pp.pprint('get_team_info')
|
pp.pprint('get_team_info')
|
||||||
pp.pprint(get_team_info('6137'))
|
pp.pprint(get_team_info('6665'))
|
||||||
|
|
||||||
pp.pprint('get_matches')
|
pp.pprint('get_matches')
|
||||||
pp.pprint(get_matches())
|
pp.pprint(get_matches())
|
||||||
|
|
Loading…
Add table
Reference in a new issue