diff --git a/fast_flights/core.py b/fast_flights/core.py index 977b241e..2c10fcfa 100644 --- a/fast_flights/core.py +++ b/fast_flights/core.py @@ -15,6 +15,80 @@ DataSource = Literal['html', 'js'] + +def _parse_aria_label(label: str) -> dict: + """Parse flight details from aria-label as fallback when CSS selectors fail. + + Google Flights always includes a structured aria-label on each flight item, + e.g.: 'From 2359 US dollars. Nonstop flight with Alaska. Leaves San Jose + Mineta International Airport at 2:25 PM on Sunday, February 15 and arrives + at Kona International Airport at 6:13 PM on Sunday, February 15. Total + duration 5 hr 48 min.' + + This is used as a fallback when the CSS class names in the HTML differ from + what the parser expects (Google obfuscates class names differently depending + on the browser fingerprint / TLS fingerprint used by the HTTP client). + """ + result = {} + + # Airline name: "flight with . Leaves" + m = re.search(r'flight with (.+?)\.\s*Leaves', label) + result['name'] = m.group(1) if m else "" + + # Departure time: "Leaves at