What is the best method to parse a User-Agent string in Python to reliably detect
- Browser
- Browser version
- OS
Or perhaps any helper library that does it
What is the best method to parse a User-Agent string in Python to reliably detect
Or perhaps any helper library that does it
You can't. Best you can get is having someone collect a database of them. You can do that yourself or there are some in Internet.
More to the point, depending on browser OSes and versions for capability detection is not a good strategy. What problem are you trying to solve?
However if you wish to parse all this on the Python side you can use the XML/INI files provided at http://browsers.garykeith.com/downloads.asp to do lookups on the user agent. This is the same file that is used in php's get_browser() function.
Th Browser Cap Parser should work. It may be a bit slow though..
Answering my own question ;)
Finally I decided to go by suggestion#1 i.e. write your own. And I am happy with the outcome. Please feel free to use/modify/send me patch etc.
It's here -> http://pypi.python.org/pypi/httpagentparser
UASparser for Python by Hicro Kee. Auto updated datafile and cache from remote server with version checking.