diff --git a/README.md b/README.md index 7b8632f..9346adf 100644 --- a/README.md +++ b/README.md @@ -51,3 +51,10 @@ Provides an API for HLTV >>> hltv.get_results() [{'team2score': 16, 'team1': 'AGO', 'team2': 'G2', 'team1score': 8, 'date': '15/2/2018', 'event': 'ESL Pro League Season 7 Europe'}, ... ] ``` + +## `get_results_by_date` + +```python +>>> hltv.get_results_by_date() +[{'team2score': 16, 'team1': 'AGO', 'team2': 'G2', 'team1score': 8, 'map': 'Inferno', 'date': '2018-2-15', 'event': 'ESL Pro League Season 7 Europe'}, ... ] +``` diff --git a/main.py b/main.py index 3a97424..b2ecf35 100644 --- a/main.py +++ b/main.py @@ -6,7 +6,13 @@ from python_utils import converters def get_parsed_page(url): - return BeautifulSoup(requests.get(url).text, "lxml") + # This fixes a blocked by cloudflare error i've encountered + headers = { + "referer": "https://www.hltv.org/stats", + "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64)" + } + + return BeautifulSoup(requests.get(url, headers=headers).text, "lxml") def top5teams(): @@ -208,6 +214,46 @@ def get_results(): return results_list +def get_results_by_date(start_date, end_date): + # Dates like yyyy-mm-dd (iso) + results_list = [] + offset = 0 + # Loop through all stats pages + while True: + url = "https://www.hltv.org/stats/matches?startDate="+start_date+"&endDate="+end_date+"&offset="+str(offset) + + results = get_parsed_page(url) + + # Total amount of results of the query + amount = int(results.find("span", attrs={"class": "pagination-data"}).text.split("of")[1].strip()) + + # All rows (