Skip to main content

Overview

The Bet365AndroidSession class provides a high-level interface for interacting with Bet365’s API endpoints. It handles TLS fingerprinting, cookie management, and anti-bot header generation automatically.

Constructor

api_url
str
required
The URL of the X-Net header generation API
api_key
str
required
API key for authenticating with the X-Net header generation service
host
str
default:"www.bet365.com"
Bet365 host domain to connect to
proxy
Optional[str]
default:"None"
HTTPS proxy URL to route requests through (format: http://user:pass@host:port)
verify
bool
default:"True"
Whether to verify SSL certificates (internally set to False for compatibility)
from bet365 import Bet365AndroidSession

session = Bet365AndroidSession(
    api_url="https://api.example.com/generate",
    api_key="your-api-key",
    host="www.bet365.com",
    proxy="http://user:[email protected]:8080"
)

Methods

go_homepage()

Initializes the session by visiting the Bet365 homepage and extracting necessary configuration.
def go_homepage()
Returns: None Raises:
  • AssertionError: If blocked by Cloudflare (403) or configuration fetch fails
Example:
session = Bet365AndroidSession(
    api_url="https://api.example.com/generate",
    api_key="your-api-key"
)
session.go_homepage()

extract_available_sports()

Retrieves the list of all available sports from Bet365.
def extract_available_sports() -> list[Sport]
Returns: list[Sport] - List of Sport objects containing name and PD identifier Example:
session.go_homepage()
sports = session.extract_available_sports()

for sport in sports:
    print(f"{sport.name}: {sport.PD}")
# Output:
# Football: #AS#B1#C1#D8#E12345#
# Basketball: #AS#B1#C1#D18#E67890#

get_sport_homepage()

Fetches the homepage data for a specific sport including available matches and odds.
def get_sport_homepage(sport: Sport)
sport
Sport
required
Sport object obtained from extract_available_sports()
Returns: None (prints match tables to console and saves response to response.txt) Example:
session.go_homepage()
sports = session.extract_available_sports()

# Get football homepage
football = next(s for s in sports if s.name == "Soccer")
session.get_sport_homepage(football)

protected_get()

Makes an authenticated GET request with anti-bot protection headers.
def protected_get(
    url: str,
    headers: Union[dict[str, str], None] = None,
    *args,
    **kwargs
)
url
str
required
The URL to make the GET request to
headers
dict[str, str] | None
default:"None"
Additional headers to include in the request
**kwargs
Any
Additional arguments passed to curl_cffi’s get() function (e.g., params, timeout)
Returns: Response - curl_cffi Response object Example:
response = session.protected_get(
    "https://www.bet365.com/leftnavcontentapi/allsportsmenu",
    params={
        "lid": "30",
        "zid": "0",
        "pd": "#AL#B1#R^1#"
    },
    headers={
        "User-Agent": "Mozilla (Linux; Android 12 Phone...) bet365/8.0.36.00",
        "X-b365App-ID": "8.0.36.00-row"
    }
)
print(response.status_code)
print(response.text)

get_x_net_header()

Generates the X-Net-Sync-Term-Android header required for anti-bot protection.
def get_x_net_header(
    url: str,
    cookie_header: str,
    post_data: bytes
) -> str
url
str
required
The URL that will be requested
Cookie header string
post_data
bytes
required
POST data bytes (empty bytes b"" for GET requests)
Returns: str - The generated X-Net header value Raises:
  • AssertionError: If the API returns a non-200 status code
Example:
from bet365.sdk import build_cookies

cookie_header = build_cookies(session.session.cookies)
x_net_header = session.get_x_net_header(
    "https://www.bet365.com/splashcontentapi/getsplashpods",
    cookie_header,
    b""
)
print(x_net_header)

Properties

session

Type: curl_cffi.requests.Session The underlying curl_cffi session object used for making HTTP requests.
# Access cookies
print(session.session.cookies)

# Make custom requests
response = session.session.get("https://example.com")

device_id

Type: str Randomly generated device UUID used to identify the session. Format: 00000000-0000-0000-XXXX-XXXXXXXXXXXX
print(session.device_id)
# Output: 00000000-0000-0000-A1B2-C3D4E5F6A7B8

zap_thread

Type: Bet365ZAPConnection | None Live data connection thread (only available in full version, not demo).
if session.zap_thread:
    print("Live data connection active")

host

Type: str The Bet365 host domain being used.

api_url

Type: str The URL of the X-Net header generation API.

api_key

Type: str API key for the X-Net header generation service.

proxy

Type: Optional[str] Configured proxy URL (if any).

Complete Example

from bet365 import Bet365AndroidSession

# Initialize session
session = Bet365AndroidSession(
    api_url="https://api.example.com/generate",
    api_key="your-api-key",
    proxy="http://user:[email protected]:8080"
)

# Setup session by visiting homepage
session.go_homepage()

# Get available sports
sports = session.extract_available_sports()
print(f"Found {len(sports)} sports")

# Get data for a specific sport
football = next(s for s in sports if "Football" in s.name)
session.get_sport_homepage(football)

# Make custom authenticated requests
response = session.protected_get(
    f"https://{session.host}/some-api-endpoint",
    params={"lid": "1"},
    headers={"X-b365App-ID": "8.0.36.00-row"}
)

if response.status_code == 200:
    print("Success!")
    print(response.text)

Build docs developers (and LLMs) love