浏览器检测Python / mod_python?
我想在数据库中保留一些有关用户和位置的统计信息。例如,我想存储“Mozilla”、“Firefox”、“Safari”、“Chrome”、“IE”等......以及版本,可能还有操作系统。
我试图从Python中找到这个字符串;
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.14) Gecko/2009090216 Ubuntu/9.04 (jaunty) Firefox/3.0.14
有没有一种有效的方法来使用 Python 或 mod_python 来检测 http 用户代理/浏览器?
I want to keep some statistics about users and locations in a database. For instance, I would like to store "Mozilla","Firefox","Safari","Chrome","IE", etc... as well as the versions, and possibly the operating system.
What I am trying to locate from Python is this string;
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.14) Gecko/2009090216 Ubuntu/9.04 (jaunty) Firefox/3.0.14
Is there an efficient way to use Python or mod_python to detect the http user agent/browser?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
HTTP_USER_AGENT
包含此信息,并将在您的应用程序使用的环境变量中传递。在 mod_python 中,这表示为:这是一个基本的 CGI 事物,但这就是 mod_python 为您提供的方式。
HTTP_USER_AGENT
contains this information, and will be passed in the environment variables your application uses. In mod_python, this is expressed as:It's a basic CGI thing, but this is how mod_python gives it to you.
杰德·史密斯建议的方法有效,但我确信还有更简单的方法。
req.headers_in 变量包含所有标头信息,您可以通过调用 mod_python 轻松访问用户代理:
使用这种方法。
The method suggested by Jed Smith works, but I was sure there was a simpler way.
The
req.headers_in
variable contains all the header info, and you can easily access the user agent using mod_python by calling:It is not necessary to call
req.add_common_vars()
when using this method.如果您使用Django框架,您会得到这样的用户代理。
非常好的插件httpagentparser提取每个细节并将其放入字典中。
通过 pip 安装工作
希望这会有所帮助...我用谷歌搜索了大约 30 分钟,直到找到有用的东西:)
Ron
If you are using the Django-Framework you get the user agent like this
The very nice plugin httpagentparser extracts every detail and puts it a dictionary.
Installation works via pip
Hope this helps... I googled about 30 min until I found something useful :)
Ron