有什么方法可以检测用户代理是来自浏览器还是应用程序?

sfa*_*tor 3 python user-agent mobile-application http-headers

我需要区分来自 HTTP 标头的 User-Agent 字符串是来自移动(iOS 和 Android)浏览器还是应用程序。是否有任何工具/库,最好是在 Python 中可以帮助我?

bag*_*rat 5

user-agents是一个相当简单的 Python 包,它解析User-Agent字符串。

from user_agents import parse

user_agent = parse(user_agent_string)
user_agent.os.family  # This will get you what you need
Run Code Online (Sandbox Code Playgroud)

因此,拥有操作系统系列,您可以判断请求是来自桌面浏览器还是移动浏览器或应用程序客户端。