app.bettersight.io/backend/services/url_utils.py

19 lines
729 B
Python

from urllib.parse import urlparse
def is_generic_homepage(url):
"""
True when `url` has no meaningful path — the bare root domain (with or
without a trailing slash, query string, or www prefix), not a
trip-specific page. Used to flag/exclude scrapes and matches that landed
on a competitor's homepage instead of an actual trip page.
Known limitation: only catches a structurally empty path — not a "soft"
generic page like /home or /en/. Not worth guarding against
speculatively; revisit if that turns out to be a real case in practice.
"""
if not url:
return False
parsed = urlparse(url if '://' in url else f'//{url}')
return (parsed.path or '').rstrip('/') == ''