Grabbing user's agent and OS type

Tim Chase python.list at tim.thechases.com
Fri Mar 11 11:39:52 EST 2011


On 03/11/2011 09:59 AM, Νικόλαος Κούρας wrote:
> ******************
> agent = os.environ['HTTP_USER_AGENT']
>
> # determination of user browser
> agent = agent.lower()
> if 'chrome' in agent:
> 	agent = 'Chrome'
> if 'firefox' in agent:
> 	agent = 'Firefox'
> if 'opera' in agent:
> 	agent = 'Opera'
> if 'safari' in agent:
> 	agent = 'Safari'
> if 'msie' in agent:
> 	agent = 'IE'
> ***************
>
> I just want to have an idea of what browser a guest is using when
> hitting my webpage.
>
> http://www.superhost.gr/?show=log
>
> now includes also that filed in the logging process.

I now have a sudden urge to use Firefox's User-Agent Switcher 
add-on to change my UA string to something like "Chrome Firefox 
MSIE Opera Safari Mozilla Lynx Links Dillo Win32 Windows Linux 
OpenBSD Mac OS X" and browse your site :)

-tkc






More information about the Python-list mailing list