The Bet365MessageParser class provides functionality to parse and query Bet365’s proprietary message format. This format is used in API responses and consists of sections separated by delimiters, with each section containing a type and key-value properties.
A list of section groups, where each group is a list of Bet365Section objects
Example:
from bet365.message_parser import Bet365MessageParser, Bet365Section# Usually created via get_parsers(), not directlysections = [[ Bet365Section("CL", {"NA": "Soccer", "PD": "#AS#B1#"}), Bet365Section("MA", {"FD": "Match Name"})]]parser = Bet365MessageParser(sections)
Returns:List[Bet365Section] - List of parsed section objectsExample:
section_strings = [ "CL;NA=Soccer;PD=#AS#B1#", "MA;FD=Team A vs Team B", "PA;OD=3/1;ID=98765"]sections = Bet365MessageParser.parse_sections_list(section_strings)for section in sections: print(f"{section.type}: {section.properties}")
Property filters to apply. Can be exact values or callable functions for custom matching.
Returns:Iterator[Tuple[int, Bet365Section]] - Iterator of (index, section) tuplesExample:
# Find all CL sections with a specific namefor idx, section in parser.find_sections("CL", NA="Soccer", include_part_index=True): print(f"Found at index {idx}: {section.get_property('NA')}")# Find sections using a custom filter functiondef has_odds(key, value): return value is not None and "/" in str(value)for idx, section in parser.find_sections("PA", OD=has_odds, include_part_index=True): print(f"Odds: {section.get_property('OD')}")# Find sections with PV property starting with specific valuefor idx, section in parser.find_sections( "CL", PV=lambda k, v: v.startswith("podcontentcontentapi") if v else False, include_part_index=True): print(f"Found pod content section at {idx}")
Show Understanding include_part_index
When include_part_index=True: Returns the matched section itself
When include_part_index=False: Returns the entire section group containing the match
Use True when you need the specific section, False when you need context around it.
data (list): List of rows, each with name, values, and extra fields
Example:
from bet365.message_parser import get_parsers, read_tableresponse = session.protected_get(...)parsers = get_parsers(response.text)for parser in parsers: # Find match group sections for idx, _ in parser.find_sections("MG", include_part_index=True): table = read_table(parser, idx, extra_properties=["IT", "CT"]) print(f"Table: {table['title']}") for row in table['data']: print(f" {row['name']}: {row['values']}") if row['extra']: print(f" Extra: {row['extra']}")
Show Table structure
Tables in Bet365’s format typically consist of:
An MG (Match Group) section as the header
MA (Market) sections for row labels
PA (Participant) sections containing odds and IDs
CO (Comment) sections for additional context
The read_table() function extracts this hierarchical structure into a flat dictionary format.