From 84cf30130744ec378183fb70274dfd27ed9fb397 Mon Sep 17 00:00:00 2001 From: marshygeek Date: Thu, 15 Feb 2018 17:46:02 +0400 Subject: [PATCH] Add User-Agent (#98) * Added User-Agent header in loading for each site * Moved common var in __init__ --- surebet/loading/__init__.py | 5 +++++ surebet/loading/marat.py | 6 ++++-- surebet/loading/olimp.py | 14 ++++++++++++-- surebet/loading/posit.py | 4 +++- 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/surebet/loading/__init__.py b/surebet/loading/__init__.py index 7e189f5..4cc0eed 100644 --- a/surebet/loading/__init__.py +++ b/surebet/loading/__init__.py @@ -7,6 +7,11 @@ package_dir = os.path.dirname(__file__) +browser_headers = { + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) " + "Chrome/63.0.3239.132 Safari/537.36", +} + class LoadException(Exception): pass diff --git a/surebet/loading/marat.py b/surebet/loading/marat.py index c0826aa..b4a3111 100644 --- a/surebet/loading/marat.py +++ b/surebet/loading/marat.py @@ -5,6 +5,7 @@ import re import requests +from surebet.loading import browser_headers from surebet.loading import log_loaded_events, check_status from surebet.loading.async import async_post, async_get @@ -20,7 +21,7 @@ def load_events(): - r = requests.get(url) + r = requests.get(url, headers=browser_headers) check_status(r.status_code) site_html = r.text @@ -74,7 +75,8 @@ def process_sport_tree(raw_sport_tree): async def get_event_details(event_id, session): req_url = details_url.format(event_id) - headers = {"Content-Type": "application/x-www-form-urlencoded"} + headers = browser_headers.copy() + headers.update({"Content-Type": "application/x-www-form-urlencoded"}) resp = await async_post(session, req_url, headers=headers, allow_empty=True) result = None diff --git a/surebet/loading/olimp.py b/surebet/loading/olimp.py index 737e694..04eb03a 100644 --- a/surebet/loading/olimp.py +++ b/surebet/loading/olimp.py @@ -18,6 +18,10 @@ "lang_id": "2", } +base_headers = { + "User-Agent": "okhttp/3.8.0", +} + sports_by_id = { 1: "soccer", 5: "basket", @@ -42,7 +46,10 @@ def get_sport_tree(): "time_shift": "0", }) - r = requests.post(req_url, headers=get_xtoken(form_data), data=form_data) + headers = base_headers.copy() + headers.update(get_xtoken(form_data)) + + r = requests.post(req_url, headers=headers, data=form_data) check_status(r.status_code) response = r.json() @@ -67,7 +74,10 @@ async def get_event_details(event_id, sport_id, session): "id": event_id, }) - resp = await async_post(session, req_url, headers=get_xtoken(form_data), data=form_data, allow_not_found=True) + headers = base_headers.copy() + headers.update(get_xtoken(form_data)) + + resp = await async_post(session, req_url, headers=headers, data=form_data, allow_not_found=True) details = resp["data"] if resp else None return {"sport_id": sport_id, "details": details} diff --git a/surebet/loading/posit.py b/surebet/loading/posit.py index 1aa7258..ed92efb 100644 --- a/surebet/loading/posit.py +++ b/surebet/loading/posit.py @@ -19,8 +19,8 @@ index_url = "https://positivebet.com/en/bets/index" xp_token = '//*[@id="login-form"]/input' - token_name = "YII_CSRF_TOKEN" + payload = { "UserLogin[rememberMe]": ["0", "1"], "yt0": '', @@ -37,6 +37,8 @@ def load(session, account=default_account): "UserLogin[password]": account["pass"], }) + session.headers.update(browser_headers) + resp = session.get(login_url) check_status(resp.status_code)