forked from gil9red/SimplePyScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathua_parser__examples.py
More file actions
53 lines (39 loc) · 1.47 KB
/
Copy pathua_parser__examples.py
File metadata and controls
53 lines (39 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
__author__ = "ipetrash"
# SOURCE: https://github.com/ua-parser/uap-python
import pprint
# pip install ua-parser
from ua_parser import user_agent_parser
ua_string = (
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 "
"(KHTML, like Gecko) Chrome/61.0.3347.109 Safari/537.36"
)
pp = pprint.PrettyPrinter(indent=4)
parsed_string = user_agent_parser.Parse(ua_string)
pp.pprint(parsed_string)
# { 'device': {'brand': None, 'family': 'Other', 'model': None},
# 'os': { 'family': 'Windows',
# 'major': '10',
# 'minor': None,
# 'patch': None,
# 'patch_minor': None},
# 'string': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 '
# '(KHTML, like Gecko) Chrome/61.0.3347.109 Safari/537.36',
# 'user_agent': { 'family': 'Chrome',
# 'major': '61',
# 'minor': '0',
# 'patch': '3347'}}
parsed_string = user_agent_parser.ParseUserAgent(ua_string)
pp.pprint(parsed_string)
# {'family': 'Chrome', 'major': '61', 'minor': '0', 'patch': '3347'}
parsed_string = user_agent_parser.ParseOS(ua_string)
pp.pprint(parsed_string)
# { 'family': 'Windows',
# 'major': '10',
# 'minor': None,
# 'patch': None,
# 'patch_minor': None}
parsed_string = user_agent_parser.ParseDevice(ua_string)
pp.pprint(parsed_string)
# {'brand': None, 'family': 'Other', 'model': None}