Giter Club home page Giter Club logo

python-user-agents's Introduction

Python User Agents

user_agents is a Python library that provides an easy way to identify/detect devices like mobile phones, tablets and their capabilities by parsing (browser/HTTP) user agent strings. The goal is to reliably detect whether:

  • User agent is a mobile, tablet or PC based device
  • User agent has touch capabilities (has touch screen)

user_agents relies on the excellent ua-parser to do the actual parsing of the raw user agent string.

Installation

Build status

user-agents is hosted on PyPI and can be installed as such:

pip install pyyaml ua-parser user-agents

Alternatively, you can also get the latest source code from Github and install it manually.

Usage

Various basic information that can help you identify visitors can be accessed browser, device and os attributes. For example:

from user_agents import parse

# iPhone's user agent string
ua_string = 'Mozilla/5.0 (iPhone; CPU iPhone OS 5_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9B179 Safari/7534.48.3'
user_agent = parse(ua_string)

# Accessing user agent's browser attributes
user_agent.browser  # returns Browser(family=u'Mobile Safari', version=(5, 1), version_string='5.1')
user_agent.browser.family  # returns 'Mobile Safari'
user_agent.browser.version  # returns (5, 1)
user_agent.browser.version_string   # returns '5.1'

# Accessing user agent's operating system properties
user_agent.os  # returns OperatingSystem(family=u'iOS', version=(5, 1), version_string='5.1')
user_agent.os.family  # returns 'iOS'
user_agent.os.version  # returns (5, 1)
user_agent.os.version_string  # returns '5.1'

# Accessing user agent's device properties
user_agent.device  # returns Device(family=u'iPhone', brand=u'Apple', model=u'iPhone')
user_agent.device.family  # returns 'iPhone'
user_agent.device.brand # returns 'Apple'
user_agent.device.model # returns 'iPhone'

# Viewing a pretty string version
str(user_agent) # returns "iPhone / iOS 5.1 / Mobile Safari 5.1"

user_agents also expose a few other more "sophisticated" attributes that are derived from one or more basic attributes defined above. As for now, these attributes should correctly identify popular platforms/devices, pull requests to support smaller ones are always welcome.

Currently these attributes are supported:

  • is_mobile: whether user agent is identified as a mobile phone (iPhone, Android phones, Blackberry, Windows Phone devices etc)
  • is_tablet: whether user agent is identified as a tablet device (iPad, Kindle Fire, Nexus 7 etc)
  • is_pc: whether user agent is identified to be running a traditional "desktop" OS (Windows, OS X, Linux)
  • is_touch_capable: whether user agent has touch capabilities
  • is_bot: whether user agent is a search engine crawler/spider

For example:

from user_agents import parse

# Let's start from an old, non touch Blackberry device
ua_string = 'BlackBerry9700/5.0.0.862 Profile/MIDP-2.1 Configuration/CLDC-1.1 VendorID/331 UNTRUSTED/1.0 3gpp-gba'
user_agent = parse(ua_string)
user_agent.is_mobile # returns True
user_agent.is_tablet # returns False
user_agent.is_touch_capable # returns False
user_agent.is_pc # returns False
user_agent.is_bot # returns False
str(user_agent) # returns "BlackBerry 9700 / BlackBerry OS 5 / BlackBerry 9700"

# Now a Samsung Galaxy S3
ua_string = 'Mozilla/5.0 (Linux; U; Android 4.0.4; en-gb; GT-I9300 Build/IMM76D) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30'
user_agent = parse(ua_string)
user_agent.is_mobile # returns True
user_agent.is_tablet # returns False
user_agent.is_touch_capable # returns True
user_agent.is_pc # returns False
user_agent.is_bot # returns False
str(user_agent) # returns "Samsung GT-I9300 / Android 4.0.4 / Android 4.0.4"

# iPad's user agent string
ua_string = 'Mozilla/5.0(iPad; U; CPU iPhone OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B314 Safari/531.21.10'
user_agent = parse(ua_string)
user_agent.is_mobile # returns False
user_agent.is_tablet # returns True
user_agent.is_touch_capable # returns True
user_agent.is_pc # returns False
user_agent.is_bot # returns False
str(user_agent) # returns "iPad / iOS 3.2 / Mobile Safari 4.0.4"

# Kindle Fire's user agent string
ua_string = 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_3; en-us; Silk/1.1.0-80) AppleWebKit/533.16 (KHTML, like Gecko) Version/5.0 Safari/533.16 Silk-Accelerated=true'
user_agent = parse(ua_string)
user_agent.is_mobile # returns False
user_agent.is_tablet # returns True
user_agent.is_touch_capable # returns True
user_agent.is_pc # returns False
user_agent.is_bot # returns False
str(user_agent) # returns "Kindle / Android / Amazon Silk 1.1.0-80"

# Touch capable Windows 8 device
ua_string = 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0; Touch)'
user_agent = parse(ua_string)
user_agent.is_mobile # returns False
user_agent.is_tablet # returns False
user_agent.is_touch_capable # returns True
user_agent.is_pc # returns True
user_agent.is_bot # returns False
str(user_agent) # returns "PC / Windows 8 / IE 10"

Running Tests

python -m unittest discover

Changelog

Version 2.2.0 (2020-08-23)

  • ua-parser >= 0.10.0 is required. Thanks @jnozsc!
  • Added get_device(), get_os() and get_browser() instance methods to UserAgent. Thanks @rodrigondec!

Version 2.1 (2020-02-08)

  • python-user-agents now require ua-parser>=0.9.0. Thanks @jnozsc!
  • Properly detect Chrome Mobile browser families. Thanks @jnozsc!

Version 2.0 (2019-04-07)

  • python-user-agents now require ua-parser>=0.8.0. Thanks @IMDagger!

Version 1.1

  • Fixes packaging issue

Version 1.0

  • Adds compatibility with ua-parser 0.4.0
  • Access to more device information in user_agent.device.brand and user_agent.device.model

Version 0.3.2

  • Better mobile detection
  • Better PC detection

Version 0.3.1

  • user_agent.is_mobile returns True when mobile spider is detected

Version 0.3.0

  • Added str/unicode methods for convenience of pretty string

Version 0.2.0

  • Fixed errors when running against newer versions if ua-parser
  • Support for Python 3

Version 0.1.1

  • Added is_bot property
  • Symbian OS devices are now detected as a mobile device

Version 0.1

  • Initial release

Developed by the cool guys at Stamps.

python-user-agents's People

Contributors

alopex4 avatar beruic avatar boreplusplus avatar dependabot[bot] avatar emmettbutler avatar eoranged avatar fatelei avatar glogiotatidis avatar hongquan avatar hwkns avatar imdagger avatar jesseginsberg avatar jnozsc avatar jwilk avatar k-wojcik avatar kulor avatar loisaidasam avatar nagesh4193 avatar petedmarsh avatar rodrigondec avatar selwin avatar stephan-nordnes-eriksen avatar tonyseek avatar xuefeng-zhu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

python-user-agents's Issues

Failed to detect Nokia N9 browser

N9 browser should give is_mobile = True

Here is the UA string:

Mozilla/5.0 (MeeGo; NokiaN9) AppleWebKit/534.13 (KHTML, like Gecko) NokiaBrowser/8.5.0 Mobile Safari/534.13

VZW edition of Galaxy S4 comes up as tablet.

The Verizon edition S4 (SCH-I545) has the user agent string "Mozilla/5.0 (Linux; Android 4.4.2; en-us; SAMSUNG SCH-I545 Build/KOT49H) AppleWebKit/537.36 (KHTML, like Gecko) Version/1.5 Chrome/28.0.1500.94 Mobile Safari/537.36"

which erroniously comes back as true in parsers.py's _is_android_tablet() line 116 due to the "SCH-" prefix.

Glancing through the other recent Samsung phones, I don't see any others using the prefix - this seems to be an odd (but widespread) case.

Samsung Galaxy S6 SM-G920T identified as tablet

In [1]: import user_agents
In [2]: agent = "Dalvik/2.1.0 (Linux; U; Android 6.0.1; SM-G920T Build/MMB29K)"
In [3]: parsed = user_agents.parse(agent)
In [4]: parsed.os
Out[4]: OperatingSystem(family='Android', version=(6, 0, 1), version_string='6.0.1')
In [5]: parsed.device
Out[5]: Device(family='Samsung SM-G920T', brand='Samsung', model='SM-G920T')
In [6]: parsed.browser
Out[6]: Browser(family='Android', version=(6, 0, 1), version_string='6.0.1')
In [7]: parsed.is_tablet
Out[7]: True
In [8]: parsed.is_mobile
Out[8]: False

The S6 should be identified as mobile instead of tablet. From my read of the code, it looks like _is_android_tablet could use some updates.

I discovered this while investigating this issue on Parse.ly's open source Android SDK.

Googlebot mobile detection does not work for the smartphone googlebot

The smartphone googlebot user agent listed here does not get detected as mobile:
Mozilla/5.0 (iPhone; CPU iPhone OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5376e Safari/8536.25 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)

This is referenced from https://developers.google.com/webmasters/mobile-sites/references/googlebot

The other feature phone googlebots do get detected as mobile.

It appears that Mobile Safari is not being picked up as the browser by the underlying ua_parser library so the check for 'Mobile' in browser does not work. I'm not sure if the fix for this is altering the ua_parser code or the code here.

Generic iOS device shows as is_mobile == False

In [14]: parsed = user_agents.parse("MyCoolApp/6 CFNetwork/808.0.2 Darwin/15.5.0")
In [15]: parsed.is_mobile
Out[15]: False
In [16]: parsed.device.family
Out[16]: 'iOS-Device'

Given that the ua_parser module recognizes this user agent as an iOS device, python-user-agents should be correctly categorizing it as is_mobile == True. One way to solve this might be to add iOS-Device to the list of mobile device families here, though I'm not sure what negative side effects that might have.

I discovered this issue as a result of this ticket on Parse.ly's open source iOS SDK.

Windows Phone Lumia

Lumia 520, OS Windows Phone 8, Amber Update

ua_string - Mozilla/5.0 (compatible; MSIE 10.0; Windows Phone 8.0; Trident/6.0; IEMobile/10.0; ARM; Touch; NOKIA; Lumia 520)
os - OperatingSystem(family='Windows', version=(), version_string='')
os.family - Windows
browser - Browser(family=u'IE Mobile', version=(10,), version_string='10')
browser.family - IE Mobile

basestring doesn't work in Python 3

After attempting to use user-agents with Python 3 I got a NameError due to the use of basestring. I put this in to quickly get it working (for me at least with a minimum of testing).

    try:
        if major is not None and isinstance(major, basestring):
            major = int(major) if major.isdigit() else major
    except NameError:
        if major is not None and isinstance(major, str):
            major = int(major) if major.isdigit() else major
    try:
        if minor is not None and isinstance(minor, basestring):
            minor = int(minor) if minor.isdigit() else minor
    except NameError:
        if minor is not None and isinstance(minor, str):
            minor = int(minor) if minor.isdigit() else minor
    try:
        if patch is not None and isinstance(patch, basestring):
            patch = int(patch) if patch.isdigit() else patch
    except NameError:
        if patch is not None and isinstance(patch, str):
            patch = int(patch) if patch.isdigit() else patch
    try:
        if patch_minor is not None and isinstance(patch_minor, basestring):
            patch_minor = int(patch_minor) if patch_minor.isdigit() else patch_minor
    except NameError:
        if patch_minor is not None and isinstance(patch_minor, str):
            patch_minor = int(patch_minor) if patch_minor.isdigit() else patch_minor

Which replaces this starting at line 40

    if major is not None and isinstance(major, basestring):
        major = int(major) if major.isdigit() else major
    if minor is not None and isinstance(minor, basestring):
        minor = int(minor) if minor.isdigit() else minor
    if patch is not None and isinstance(patch, basestring):
        patch = int(patch) if patch.isdigit() else patch
    if patch_minor is not None and isinstance(patch_minor, basestring):
        patch_minor = int(patch_minor) if patch_minor.isdigit() else patch_minor

I am sure there is a more elegant fix that I am not going to bother looking up this late at night. I might come back to this later.

Speed Issues

The Python implementation of user-parser is very slow.
Do you guys use the CPP version of the ua-parser or the Python one? If not, do you think Cython`izing the CPP version would be possible? Also, I am thinking that vectorizing this function would also be beneficial.

Add all install requirements to setup.py

In the readme it tells people to install pyyaml and ua-parser alongside this library. ua-parser seems to be included in the setup.py, but pyyaml is not. I'm up to make PR, but I don't know what the minimum required version of pyyaml is. Could you add pyyaml to the setup.py and edit the readme?

How to modify regexes.yaml and make it work?

I found some mobile Android devices' brand were incorrectly recognized as "Generic_Android", so I tried to modify regexes.yaml. But when I re-imported ua parse, it didn't work.

For example, the original setting for Xiaomi is
#########

XiaoMi

@ref: http://www.xiaomi.com/event/buyphone

#########
regex: '; (MI \d[^;/]|MI-ONE Plus) Build/'
device_replacement: 'XiaoMi $1'
brand_replacement: 'XiaoMi'
model_replacement: '$1'

I rewrote the pattern as below, but it didn't work as I expected.

  • regex: '; (MI \d[^;/]|MI-ONE Plus|HM \w[^;/]*) Build/'

The user agent string is this:
"Mozilla/5.0 (Linux; Android 4.4.4; HM NOTE 1LTE Build/KTU84P) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/33.0.0.0 Mobile Safari/537.36 Wochacha/8.3.0"

ascii ordinal not in range for INCO AIR(r) device User Agents.

To Reproduce

from user_agents import parse
parse("Mozilla/5.0 (Linux; Android 4.4.2; INCO AIR® Build/KOT49H) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/30.0.0.0 Mobile Safari/537.36 Instagram 7.7.0 Android (19/4.4.2; 240dpi; 480x854; Inco Air/INCO; INCO AIR®; h3466; mt6582; es_US)")

[New bot] Haosou spider

I found a bot that is not currently in the bot database. It has the signature: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.89 Safari/537.1; 360Spider(compatible; HaosouSpider; http://www.haosou.com/help/help_3_2.html)

Nexus 5 is identified as tablet

I think there is an issue with detecting Nexus 5/6 as mobile devices:
example:

from user_agents import parse
ua = 'Dalvik/2.1.0 (Linux; U; Android 5.1; Google Nexus 5 - 5.1.0 - API 22 - 1080x1920 Build/LMY47D)'
user_agent = parse(ua)

result:
user_agent.is_tablet will be True and and user_agent.is_mobile will be False.

Thanks.

Very slow!

Great library makes it so easy to parse useragents but i seem to be using it wrong for i have been using it to parse apache access_log files of about 10 milion combined lines in about 3 hours. With cProfile i found i was spend the the majority of the time in user_agents and so after commenting out the user_agents.parse() call was able to parse all 10 million lines in 40 mins.

Is this normal or am i using it wrong?

Making it lazy loaded

Hi,

Thanks for this great package, I have a suggestion that I think improves its usages. In case of using it as middleware it'd be great if you could make it lazy loaded so that it doesn't process request if it wasn't needed, it could only occur when server needs user-agent information.

Thanks

Issue with parsing Googlebot user agents

user-agent-string: Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)

Traceback (most recent call last):
user_agent = parse(ua_string)
File "/../lib/python2.7/site-packages/user_agents/parsers.py", line 226, in parse
return UserAgent(user_agent_string)
File "/.../local/lib/python2.7/site-packages/user_agents/parsers.py", line 129, in init
self.device = parse_device(**ua_dict['device'])
TypeError: parse_device() takes exactly 3 arguments (1 given)

version: 1.0.1

This was returning without any issues in 0.3.2 earlier though. Problem occuring only since 1.0.1 . regression ?

More user-agents exhibiting this behavior:

Mozilla/5.0 (Linux; Android 4.2.1; en-us; Nexus 5 Build/JOP40D) AppleWebKit/535.19 (KHTML, like Gecko; googleweblight) Chrome/38.0.1025.166 Mobile Safari/535.19

Mozilla/5.0 (iPhone; CPU iPhone OS 8_3 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12F70 Safari/600.1.4 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)

FYI

Samsung GT-P3113 and SM-T110 is identified as Generic

I'm guessing that these two regex in regexes.yaml should have worked but don't appear to do so.

  - regex: '; *(SAMSUNG-)?(GT\-[BINPS]\d{4}[^\/]*)(\/[^ ]*) Build'

  - regex: '; *((?:SCH|SGH|SHV|SHW|SPH|SC|SM)\-[A-Za-z0-9 ]+)(/?[^ ]*)? Build'

These are the failing cases:

>>> ua_string = "Mozilla/5.0 Linux U Android 4.2.2 es-us GT-P3113 Build/JDQ39 AppleWebKit/534.30 KHTML like Gecko Version/4.0 Safari/534.30"
>>> parsed_string = user_agent_parser.Parse(ua_string)
>>> pp.pprint(parsed_string)
{   'device': {   'brand': 'Generic',
                  'family': 'Generic Smartphone',
                  'model': 'Smartphone'},
    'os': {   'family': 'Android',
              'major': '4',
              'minor': '2',
              'patch': '2',
              'patch_minor': None},
    'string': 'Mozilla/5.0 Linux U Android 4.2.2 es-us GT-P3113 Build/JDQ39 AppleWebKit/534.30 KHTML like Gecko Version/4.0 Safari/534.30',
    'user_agent': {   'family': 'Android',
                      'major': '4',
                      'minor': '2',
                      'patch': '2'}}

>>> ua_string = "Mozilla/5.0 Linux Android 4.2.2 SM-T110 Build/JDQ39 AppleWebKit/537.36 KHTML like Gecko Chrome/49.0.2623.91 Safari/537.36"
>>> parsed_string = user_agent_parser.Parse(ua_string)
>>> pp.pprint(parsed_string)
{   'device': {   'brand': 'Generic',
                  'family': 'Generic Smartphone',
                  'model': 'Smartphone'},
    'os': {   'family': 'Android',
              'major': '4',
              'minor': '2',
              'patch': '2',
              'patch_minor': None},
    'string': 'Mozilla/5.0 Linux Android 4.2.2 SM-T110 Build/JDQ39 AppleWebKit/537.36 KHTML like Gecko Chrome/49.0.2623.91 Safari/537.36',
    'user_agent': {   'family': 'Chrome',
                      'major': '49',
                      'minor': '0',
                      'patch': '2623'}}

Conflict with python 3.5?

I was trying to install with anaconda and resulted in the following error message:

UnsatisfiableError: The following specifications were found to be in conflict:

  • python 3.5*
  • user-agents 1.1.0* -> python 2.7*

Any advice?

Thanks.

Support for embeeded browsers (Facebook app)

Hi, here is the user agent if you need it:

Mozilla/5.0 (Linux; U; Android 4.1.2; en-us; GT-S6310 Build/JZO54K) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30 [FB_IAB/FB4A;FBAV/29.0.0.23.13;]

Microsoft Edge is not detected

Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.10136

>>> parse( 'Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.10136' ).device
Device(family='Other', brand=None, model=None)

https://stackoverflow.com/questions/30591706/what-is-the-user-agent-string-name-for-microsoft-edge

MS details for user-agent string in Edge
https://msdn.microsoft.com/en-us/library/hh869301(v=vs.85).aspx

Issue with device being returned in User Agent

I'm having a traceback like this:

Traceback (most recent call last):
  File "/Users/heynemann/Dropbox/dev/thumby-dashboard/tests/elasticsearch/test_request_model.py", line 97, in test_can_process_request_log_from_cloudfront
    request_id = Request.perform(log_line)
  File "/Users/heynemann/Dropbox/dev/thumby-dashboard/thumby_dashboard/models/elasticsearch/request.py", line 76, in perform
    items = parse(cloudfront_log_lines)
  File "/Users/heynemann/.virtualenvs/thumby/lib/python2.7/site-packages/cloudfront_log_parser/__init__.py", line 42, in parse
    result.append(parse_line(line))
  File "/Users/heynemann/.virtualenvs/thumby/lib/python2.7/site-packages/cloudfront_log_parser/__init__.py", line 81, in parse_line
    parse_user_agent(response, log_line[10])
  File "/Users/heynemann/.virtualenvs/thumby/lib/python2.7/site-packages/cloudfront_log_parser/__init__.py", line 109, in parse_user_agent
    user_agent = user_agent_parse(response.user_agent)
  File "/Users/heynemann/.virtualenvs/thumby/lib/python2.7/site-packages/user_agents/parsers.py", line 226, in parse
    return UserAgent(user_agent_string)
  File "/Users/heynemann/.virtualenvs/thumby/lib/python2.7/site-packages/user_agents/parsers.py", line 129, in __init__
    self.device = parse_device(**ua_dict['device'])
TypeError: parse_device() got an unexpected keyword argument 'brand'

The user agent being parsed is:

curl/7.37.1

Any ideas on what might be causing it?

is_bot property is not implemented well

@property
    def is_bot(self):
        return True if self.device.family == 'Spider' else False

Is it okay to update current implementation of is_bot property? Have any idea?

how to get AppleWebKit ?

for example
Mozilla/5.0 (iPhone; CPU iPhone OS 5_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9B179 Safari/7534.48.3

how to get AppleWebKit ?

parse does not detect a touch capable user agent

It seems that parse does not detect some touch screen user agents

>>> user_agent = u'Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; Touch; LCJB; rv:11.0) like Gecko'
>>> parse(user_agent).is_touch_capable
False

version = 1.1.0

any ideas ?

User Agent browser identification failure

The following gets identified as "Safari" without a version number, but given the X11 in the string, I have my doubts:

Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/534.34 (KHTML, like Gecko) Qt/4.8.2 Safari/534.34

I'm not sure which browser this user agent string comes from, but Google wasn't too helpful

is_mobile error

user agent:
Mozilla/5.0 (Linux; Android 6.0.1; Redmi Note 4X Build/MMB29M; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/53.0.2785.49 Mobile MQQBrowser/6.2 TBS/043409 Safari/537.36 MicroMessenger/6.5.13.1100 NetType/WIFI Language/zh_CN

is_mobile return false(should be true)

For Macintosh, Brand is None

I have verified that this is still true.

In the example on https://github.com/ua-parser/uap-python/blob/master/README.rst

It seems that "Macintosh" should be result in a brand of "Apple". Model or family should be "Macintosh".

>>> from ua_parser import user_agent_parser
>>> import pprint
>>> pp = pprint.PrettyPrinter(indent=4)
>>> ua_string = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.104 Safari/537.36'
>>> parsed_string = user_agent_parser.ParseDevice(ua_string)
>>> pp.pprint(parsed_string)
{   'brand': None,
    'family': 'Other',
    'model': None}

In addition, iPad hardware isn't tagged either:

>>> ua_sring = "Mozilla/5.0 iPad CPU OS 9_2_1 like Mac OS X AppleWebKit/601.1.46 KHTML like Gecko Mobile/13D15 Safari/601.1.46 Sleipnir/4.2.2m"
>>> parsed_string = user_agent_parser.ParseDevice(ua_string)
>>> pp.pprint(parsed_string)
{   'brand': None, 'family': 'Other', 'model': None}

Firefox OS issues

Hi there. There's currently some problems with parsing Firefox OS ua strings:

Firefox OS Mobile:

>>> ua_string = 'Mozilla/5.0 (Mobile; rv:26.0) Gecko/26.0 Firefox/26.0'
>>> b = parse(ua_string)
>>> b.device
Device(family='Other')
>>> b.browser
Browser(family=u'Firefox Mobile', version=(26,), version_string='26')
>>> b.is_tablet
False
>>> b.is_mobile
False
>>> b.is_touch_capable
False
>>> b.os
OperatingSystem(family=u'Firefox OS', version=(), version_string='')

is_mobile and is_touch_capable should be true.

Firefox OS for tablets:

>>> ua_string = 'Mozilla/5.0 (Tablet; rv:29.0) Gecko/29.0 Firefox/29.0'
>>> b = parse(ua_string)
>>> b.is_mobile
False
>>> b.is_touch_capable
False
>>> b.is_tablet
False
>>> b.os
OperatingSystem(family='Other', version=(), version_string='')
>>> b.device
Device(family='Other')

is_mobile and is_touch_capable should be true. os.family should report Firefox OS -- I've made a pull request against ua-parser for that though: tobie/ua-parser#331

Add ability to dump json

Dumping the object to JSON could be great. As far as i know namedtuples are not serializeable so i use jsno.dumps(ua.browser.__dict__). Plus, Exposing the ua_parser parsed dict as a property as well.

The true added value here is the is_mobile/pc/tablet/touch properties.

Improvements for User Agent recognition

Here are some improvements I would recommend to apply. Please, also deploy the changes to the Django package.

These type of User Agents are not being recognized as "tablet":

Mozilla/5.0 (iPad; CPU OS 10_3_1 like Mac OS X) AppleWebKit/603.1.30 (KHTML, like Gecko) Mobile/14E304 [FBAN/FBIOS;FBAV/89.0.0.52.71;FBBV/55613772;FBDV/iPad5,4;FBMD/iPad;FBSN/iOS;FBSV/10.3.1;FBSS/2;FBCR/movistar;FBID/tablet;FBLC/es_ES;FBOP/5;FBRV/0]

These type of User Agents are not being recognized as "PC":

Mozilla/5.0 (X11; CrOS x86_64 9202.66.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.148 Safari/537.36

These types of User Agents are not being recognized as "mobile":

Mozilla/5.0 (iPod touch; CPU iPhone OS 10_2_1 like Mac OS X) AppleWebKit/602.4.6 (KHTML, like Gecko) Mobile/14D27 [FBAN/FBIOS;FBAV/89.0.0.52.71;FBBV/55613772;FBDV/iPod7,1;FBMD/iPod touch;FBSN/iOS;FBSV/10.2.1;FBSS/2;FBCR/;FBID/phone;FBLC/es_LA;FBOP/5;FBRV/56133369]

Mozilla/5.0 (Mobile; ALCATELOneTouch4019A; rv:28.0) Gecko/28.0 Firefox/28.0

It should be great to add the "is_smart_tv" feature for these type of User Agents:

Mozilla/5.0 (SMART-TV; Linux; Tizen 2.4.0) AppleWebkit/538.1 (KHTML, like Gecko) SamsungBrowser/1.1 TV Safari/538.1

Need to specify ua-parser version in setup.py

A project I'm working on uses user-agents 0.3.2 and I just ran into an issue where pip install installed ua-parser 0.5.0, which is incompatible with user-agents 0.3.2. To prevent this from happening in the future, setup.py should specify which versions of ua-parser are compatible.

dont work on ubuntu 14.04

i install ua-parser and user-agents on ubuntu via pip ...

but when i run python script always get me error

ua = parse('Mozilla/5.0 (iPhone; CPU iPhone OS 5_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9B179 Safari/7534.48.3')
File "/usr/local/lib/python2.7/dist-packages/user_agents/parsers.py", line 205, in parse
return UserAgent(user_agent_string)
File "/usr/local/lib/python2.7/dist-packages/user_agents/parsers.py", line 113, in init
self.device = parse_device(**ua_dict['device'])
TypeError: parse_device() got an unexpected keyword argument 'brand'

Firefox for Android issues

Hi there,

A few issues with Firefox for Android user agents:

>>> ua_string = 'Mozilla/5.0 (Android; Mobile; rv:26.0) Gecko/26.0 Firefox/26.0'
>>> b = parse(ua_string)
>>> b.browser
Browser(family=u'Firefox Mobile', version=(26,), version_string='26')
>>> b.is_touch_capable
True
>>> b.is_tablet
True
>>> b.os
OperatingSystem(family='Android', version=(), version_string='')
>>> b.is_mobile
False
>>> 

is_tablet should be false, is_mobile should be true.

Samsung phones shown as tablets (SGH-I527 & SPH-L600

There are also 2 more models which are shown as tablets.

Samsung-SGH-I527, with this user agent
Mozilla/5.0 (Linux; U; Android 4.2.2; en-us; SAMSUNG-SGH-I527 Build/JDQ39) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Safari/534.30 FB_IAB/FB4A;FBAV/104.0.0.17.71;

Samsung-SPH-L600
Mozilla/5.0 (Linux; U; Android 4.2.2; en-us; SPH-L600 Build/JDQ39) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Safari/534.30 FB_IAB/FB4A;FBAV/85.0.0.15.70;

I debugged function parse in parsers, the problem is that there is no 'Mobile' in user agent, before Safari, so this automatically becomes tablet. I thought that this could be related with screen size and resolution. They are 6.3 inches.

I've noticed that there are more Samsung models in issues, so I would like to know if there is an interest to solve these issues with them. Thanks

Surface tablets are seen as non-touch-capable pc

I'm having an issue with a Surface. User agent is Mozilla/5.0 (Windows NT 6.3; ARM; Trident/7.0; Touch; rv:11.0 and it's not detexcted as a touch-capable device:

{'device': Device(family='Other'),
'browser': Browser(family=u'IE', version=(11,), version_string='11'),
'os': OperatingSystem(family='Windows', version=(), version_string=''),
'ua_string': 'Mozilla/5.0 (Windows NT 6.3; ARM; Trident/7.0; Touch; rv:11.0) like Gecko'}

Samsung Galaxy Note 3 N9005 is identified as tablet

>>> from user_agents import parse
>>> ua = parse('Mozilla/5.0 (Linux; Android 4.4.2; SM-N9005 Build/KOT49H) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/37.0.0.0 Mobile MQQBrowser/6.2 TBS/036215 Safari/537.36 MicroMessenger/6.3.16.49_r03ae324.780 NetType/WIFI Language/zh_CN')
>>> ua.is_mobile
False
>>> ua.is_tablet
True

And the expected result: ua.is_mobile should be True and ua.is_tablet should be False .

Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.