浏览器检测Python / mod_python? [英] Browser Detection Python / mod_python?

查看:116
本文介绍了浏览器检测Python / mod_python?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在数据库中保留一些有关用户和位置的统计信息。例如,我想存储Mozilla,Firefox,Safari,Chrome,IE等...以及版本,可能还有操作系统。

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.

我想从Python找到的是这个字符串;

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

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用户代理/浏览器?

Is there an efficient way to use Python or mod_python to detect the http user agent/browser?

推荐答案

HTTP_USER_AGENT 包含此信息,并将在您的应用程序使用的环境变量中传递。在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:

def my_request_handler(req):
    req.add_common_vars()
    agent = req.subprocess_env.get("HTTP_USER_AGENT")

    # `agent` now contains the full user agent of the browser, or None

这是一个基本的CGI事情,但这就是mod_python给你的方式。

It's a basic CGI thing, but this is how mod_python gives it to you.

这篇关于浏览器检测Python / mod_python?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆