Is there any way to detect if a user agent is from a browser or an app?

孤街浪徒 提交于 2019-12-11 04:03:22

问题


I need to differentiate whether a User-Agent string from an HTTP header is from a mobile (iOS & Android) browser or a app. Is there any tool/library, preferably in Python which can help me with that?


回答1:


user-agents is a fairly simple package for Python, which parses the User-Agent string.

from user_agents import parse

user_agent = parse(user_agent_string)
user_agent.os.family  # This will get you what you need

So having the OS family you can judge whether the request is made from a desktop browser or mobile browser or app client.



来源:https://stackoverflow.com/questions/30963473/is-there-any-way-to-detect-if-a-user-agent-is-from-a-browser-or-an-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!