有没有办法检测用户代理是来自浏览器还是应用程序? [英] Is there any way to detect if a user agent is from a browser or an app?
本文介绍了有没有办法检测用户代理是来自浏览器还是应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要区分来自HTTP标头的User-Agent字符串是来自移动(iOS和Android)浏览器还是应用程序。是否有任何工具/库,最好是用Python来帮助我?
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?
推荐答案
user-agents 是一个相当简单的Python包,解析 User-Agent
字符串。
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
因此,您可以拥有OS系列判断请求是来自桌面浏览器还是移动浏览器或应用客户端。
So having the OS family you can judge whether the request is made from a desktop browser or mobile browser or app client.
这篇关于有没有办法检测用户代理是来自浏览器还是应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文