I tried using httpagentparser to parse the User Agent. If it is a quick method, you can use it like this.
import httpagentparser
user_agent = 'Mozilla/5.0 (X11; U; Linux i686; en-US) AppleWebKit/532.9 (KHTML, like Gecko) Chrome/5.0.307.11 Safari/532.9'
httpagentparser.simple_detect(user_agent)
# ('Linux', 'Chrome 5.0.307.11')
In the case of httpagentparser.detect ()
, User Agent information can be taken in a slightly finer unit.
httpagentparser.detect(user_agent)
# {'platform': {'version': None, 'name': 'Linux'}, 'os': {'name': 'Linux'}, 'bot': False, 'browser': {'version': '5.0.307.11', 'name': 'Chrome'}}
It also supports Python 3. It may be useful if you need to write a process according to the User Agent.
Recommended Posts