Parse User Agent in Python

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

Parse User Agent in Python
Parse XML in Python
Get your current location and user agent in Python
Quadtree in Python --2
Python in optimization
Metaprogramming in Python
Python 3.3 in Anaconda
Geocoding in python
SendKeys in Python
Meta-analysis in Python
Unittest in python
Epoch in Python
Discord in Python
Sudoku in Python
DCI in Python
quicksort in python
nCr in python
N-Gram in Python
Programming in python
Plink in Python
Constant in python
Lifegame in Python.
FizzBuzz in Python
Sqlite in python
StepAIC in Python
N-gram in python
LINE-Bot [0] in Python
Csv in python
Disassemble in Python
Reflection in Python
Constant in python
nCr in Python.
format in python
Scons in Python3
Puyo Puyo in python
python in virtualenv
PPAP in Python
Quad-tree in Python
Reflection in Python
Chemistry in Python
Hashable in python
DirectLiNGAM in Python
LiNGAM in Python
Flatten in python
flatten in python
3 ways to parse time strings in python [Note]
Let's parse the git commit log in Python!
Sorted list in Python
Daily AtCoder # 36 in Python
Daily AtCoder # 2 in Python
Implement Enigma in python
Daily AtCoder # 32 in Python
Daily AtCoder # 18 in Python
Singleton pattern in Python
File operations in Python
Key input in Python
Daily AtCoder # 33 in Python
Logistic distribution in Python
Daily AtCoder # 7 in Python
LU decomposition in Python
One liner in Python