regex - Http user agent parser in python -
i wanted parse user agent string in python , classify browser in following categories as
1) browser name
2) browser version
3) os/platform name
4) os/platform version
5) device type : either mobile/desktop/tablet/other
if mobile/tablet
6) manufaturer/vendor name
7) model no
so, external library can use achieve task , wanted stuff offline without internet connection. have database need classify it.
# import lib ua_parser import user_agent_parser # parse user agent user_agent_parser.parse(request.meta.get('http_user_agent')) print result_dict['user_agent'] # {'major': '5', 'minor': '1', 'family': 'mobile safari', 'patch': none} print result_dict['os'] # {'major': '5', 'patch_minor': none, 'minor': '1', 'family': 'ios', 'patch': none} print result_dict['device'] # {'is_spider': false, 'is_mobile': true, 'family': 'iphone'}
the code samples above recognizable can use them; using user agent information simple, , api well. done tobie nice library.
Comments
Post a Comment