File size: 706 Bytes
eb8c9be | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | import re
BLOCKED_USER_AGENT_PATTERNS = [
r"\bheadless(?:chrome)?\b",
r"\bphantomjs?\b",
r"\bselenium\b",
r"\bpuppeteer\b",
r"\bplaywright\b",
r"\bwpdt\b",
r"\bwebdriver\b",
r"\bpython-requests\b",
r"\bgo-http-client\b",
r"\bcurl\b",
r"\bwget\b",
r"\bscrapy\b",
r"\bhttpclient\b",
r"\blibwww\b",
r"\bjakarta\b",
r"\bhttpx\b",
]
def is_obvious_bot_user_agent(user_agent):
"""Return True only for clearly automated or non-browser user agents."""
ua = (user_agent or "").strip().lower()
if not ua:
return True
return any(re.search(pattern, ua) for pattern in BLOCKED_USER_AGENT_PATTERNS)
|