HTTP_USER_AGENT Parsing

brueckd at tbye.com brueckd at tbye.com
Mon Jul 15 14:52:58 EDT 2002


On Mon, 15 Jul 2002, Olly Smith wrote:

> I'm a bit of a newbie to Python, and in my quest to generate nice HTML
> content, I need a way to work out what browsers clients are using from their
> HTTP_USER_AGENT strings.
> 
> Any pointers?

- Googling for lists of User Agent strings will give you sample Javascript
to determine client platform and browser based on user agent value - this
is pretty easy to port to Python. 

- The same Google search will turn up lists of known user agent strings,
which will be useful for your test code. 

- User agent strings are not 100% reliable, but few people change them, so
they are fairly accurate (you can generally even detect browsers like
Opera, even when they are reporting themselves as IE).

- Also check the HTTP spec, as it list the official format of user agent
strings. It's basically a list of names, each followed by an optional
version number and an optional list of additional info. On the end of the
line can be an optional language code too, I think, e.g.  "[en]".

- For most people it's not worth the effort to invest too much time doing 
browser-specific HTML. ;-)


HTH,
-Dave






More information about the Python-list mailing list