Simple parser for HLTV.org team stats and matches (using requests and bs4)
Project description
Hi, I analyze hltv.org as a part of my pet project. This parser can help you build a prematch analytics dataset with data from Team stats and Analytics pages.
Install
pip install hltv-stats
Usage
HLTVMatch provides public methods for Analytics, use filename parameter to save data to a file.
from hltv_stats import HLTVMatch
match_url = "/matches/2361342/natus-vincere-vs-outsiders-iem-katowice-2023"
match = HLTVMatch(match_url)
match.parse_analytics_summary(filename=None)
Response:
[{'team': 'natus-vincere',
'indicator': 'plus',
'insight': 'natus vincere has better form ranking',
'match_id': '2361342'},
...
]
match.parse_head_to_head()
Response:
[{'player_team': 'natus-vincere',
'player_nickname': 's1mple',
'table_3_months': '1.13',
'table_event': '1.17',
'match_id': '2361342'},
...
]
match.parse_pick_ban_stats()
Response:
[{'analytics_map_name': 'mirage',
'team': 'natus-vincere',
'analytics_map_stats_pick_percentage': '39%',
'analytics_map_stats_ban_percentage': '0%',
'analytics_map_stats_win_percentage': '29%',
'analytics_map_stats_played': '7',
'analytics_map_stats_comment': 'First pick',
'match_id': '2361342'},
...
]
match.parse_analytics_center() method combines all above methods and returns a tuple of lists.
HLTVTeam provides public methods for parsing Team stats page, with filtering by time using time_filter parameter, use filename parameter to save data to a file.
from hltv_stats import HLTVTeam
team = HLTVTeam("/4608/natus-vincere")
#You can use match_id to assign team's current state(statistic) to specific match
#this will add match_id field to all json files
team.match_id = match.match_id
#time_filter: 3 - last 3 months, 6 - last 6 months, 0 - all time, ...
team.parse_matches(time_filter=1) #returns list of played matches in json format
team.parse_players(time_filter=1) #returns list of team players' statistics in json format
team.parse_maps(time_filter=1) #returns maps statistics in json format
team.parse_events(time_filter=1) #returns events statistics in json format
team.parse_all_stats(time_filter=1)
.parse_all_stats(time_filter=1) method combines all above methods and returns a tuple of lists.
parse_upcoming_matches() method parses all upcoming matches from Match page.
#Parse upcoming matches and save to json files
#:param months: list of months to parse, i.e. [1,3] <=> [last month, last 3 months]
#:param with_teams: bool, if True, parse teams' statistic as well
from hltv_stats import parse_upcoming_matches
parse_upcoming_matches(months=[1], with_teams=True)
Result folder tree contains json files with all match data, and team data if with_teams=True.
.
├── configs - contains 2 config files: which holds data about all parsed matches and teams and are used by is_parsed() method to check if match is already parsed and skips it.
├── output
│ ├── matches
│ └── teams
Also check out example.ipynb or contact me.
🤝 Contributing
Contributions, issues and feature requests are welcome!
Feel free to check issues page.
Show your support
Give a ⭐️ if this project helped you!
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file hltv_stats-0.1.7.tar.gz.
File metadata
- Download URL: hltv_stats-0.1.7.tar.gz
- Upload date:
- Size: 8.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.3.2 CPython/3.9.12 Darwin/21.6.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0a86f2eb43b08ffce00a75fc4c924898fd47d34252bf6eb272673ce486425fa3
|
|
| MD5 |
f1a9bc3374b4c99718c5d5e43338b905
|
|
| BLAKE2b-256 |
a1cb9a06eec4265555d373f2eb874f6c00ac77ad6ab0bc3934c716be1f0aef07
|
File details
Details for the file hltv_stats-0.1.7-py3-none-any.whl.
File metadata
- Download URL: hltv_stats-0.1.7-py3-none-any.whl
- Upload date:
- Size: 8.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.3.2 CPython/3.9.12 Darwin/21.6.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
25335c70357edbfc8fd5cf8b631ecfcc6d8cb1471f79591770a5cae0517b0dff
|
|
| MD5 |
14273b1f0030982f2738b75e105baa82
|
|
| BLAKE2b-256 |
6cfd883af5aa8b4388b7d95357d5ad0c2e7bdf335c3c6f7d2abb4c74bcb6f821
|