shon / httpagentparser Goto Github PK
View Code? Open in Web Editor NEWPython HTTP Agent Parser
Home Page: http://pypi.python.org/pypi/httpagentparser/
License: MIT License
Python HTTP Agent Parser
Home Page: http://pypi.python.org/pypi/httpagentparser/
License: MIT License
I am having the issue where and Ipad or Nokia Lumia is detected they return a version for dist and os. I only want a version for one or the other. How could this be fixed??
What I have:
"Mozilla/5.0 (iPad;U;CPU OS 5_1_1 like Mac OS X; zh-cn)AppleWebKit/534.46.0(KHTML, like Gecko)CriOS/19.0.1084.60 Mobile/9B206 Safari/7534.48.3"
What parser tells me:
{'bot': False,
'browser': {'name': 'ChromeiOS', 'version': '19.0.1084.60'},
'dist': {'name': 'IPad', 'version': '5.1.1'},
'os': {'name': 'iOS', 'version': 'U;CPU'},
'platform': {'name': 'iOS', 'version': '5.1.1'}}
the following user agent is detected as opera
Mozilla/5.0 (Linux; Android 8.0.0; Nexus 5X Build/OPR6.170623.023) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.84 Mobile Safari/537.36
the problem is: OPR6.170623.023
I would appreciate your assistance since its affecting production,
thanks.
User agent:
Mozilla/5.0 (Linux; Android 8.1.0) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/76.0.3809.111 Mobile Safari/537.36
Parsed:
{
'platform': {
'name': 'Android',
'version': '8.1.0) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/76.0.3809.111 Mobile Safari/537.36'
},
'os': {
'name': 'Linux'
},
'bot': False,
'dist': {
'name': 'Android',
'version': '8.1.0) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/76.0.3809.111 Mobile Safari/537.36'
},
'browser': {
'name': 'Chrome',
'version': '76.0.3809.111'
}
}
I get an error trying to parse such user agent "CFNetwork/548.0.4 Darwin/11.0.0" it is user agent for Apple iPhone SDK requests.
It will be nice to add a new type of "browser" for bot/spiders like this:
"Mozilla/5.0 (compatible; Baiduspider/2.0; +http://www.baidu.com/search/spider.html)"
pip install/easy_install called in a virtualenv -p python3
I checked
http://guide.python-distribute.org/creation.html your setup is OK
I checked your MANIFEST.in OK
I checked the presence of README.rst it is OK
I checked the doc, you play by the rules.
I am clueless. Removing l7 in setup.py and doing
python /home/jul/src/parse3/build/httpagentparser/setup.py install works however.
Downloading/unpacking httpagentparser
Real name of requirement httpagentparser is httpagentparser
Downloading httpagentparser-1.1.0.tar.gz
Running setup.py egg_info for package httpagentparser
Traceback (most recent call last):
File "", line 14, in
File "/home/jul/src/parse3/build/httpagentparser/setup.py", line 7, in
long_description=file("README.rst").read(),
NameError: name 'file' is not defined
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "", line 14, in
File "/home/jul/src/parse3/build/httpagentparser/setup.py", line 7, in
long_description=file("README.rst").read(),
NameError: name 'file' is not defined
For example, this UA spotted in the wild:
Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; SLCC1; .NET CLR 2.0.50727; InfoPath.1; .NET CLR 3.5.30729; .NET CLR 3.0.30618; .NET4.0C)
Detects as:
{'os': {'version': 'XP', 'name': 'Windows'}, 'browser': {'version': '6.0', 'name': 'Microsoft Internet Explorer'}}
When it's actually IE8.
I traced the problem to the default getVersion implementation, which favours the last occurrence of MSIE in the version string.
I write a new one on the MSIE class, which favours the first one instead:
class MSIE(Browser):
look_for = "MSIE"
skip_if_found = ["Opera"]
name = "Microsoft Internet Explorer"
version_splitters = [" ", ";"]
def getVersion(self, agent):
parts = agent.split(self.look_for + self.version_splitters[0])
return parts[min(len(parts) - 1, 1)].split(self.version_splitters[1])[0].strip()
My one grabs the FIRST version detected rather than the last one.
I haven't provided this as a pull request, because the tests for MSIE are non-existent currently, so I have no idea if my change breaks a bunch of UAs in the wild.
I added a test case for this UA at least:
('Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; SLCC1; .NET CLR 2.0.50727; InfoPath.1; .NET CLR 3.5.30729; .NET CLR 3.0.30618; .NET4.0C)',
('Windows XP', 'Microsoft Internet Explorer 8.0'),
{'os': {'version': 'XP', 'name': 'Windows'}, 'browser': {'version': '8.0', 'name': 'Microsoft Internet Explorer'}},),
I'd suggest adding a bunch of MSIE test cases first.
I experienced a problem when parsing the browser version of a visitor on my website, and it boils down to that :
>>> import httpagentparser
>>> result = httpagentparser.detect("Opera/9.64(Windows NT 5.1; U; en) Presto/2.1.1")
>>> print result
{'platform': {'version': 'XP', 'name': 'Windows'}, 'os': {'version': 'XP', 'name': 'Windows'}, 'browser': {'version': '9.64(Windows', 'name': 'Opera'}}
I think it's because there should be a space between 4
and (
but still, this is an existing Opera user agent (http://www.useragentstring.com/Opera9.64_id_13933.php).
Thank you
Is there interest in updating support IE Compatibilty modes? Currently all compatibilty mode user agent strings return as showing Internet Explorer 7.0
Sample user agent:
Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET4.0C; .NET4.0E; InfoPath.3; MS-RTC LM 8)
Current detection:
{'os': {'version': '7', 'name': 'Windows'}, 'browser': {'version': '7.0', 'name': 'Microsoft Internet Explorer'}}
Proposed detection:
{'os': {'version': '7', 'name': 'Windows'}, 'browser': {'version': '8.0 Compatibility View', 'name': 'Microsoft Internet Explorer'}}
The UA string that I get is this and I see this recognized as IOS.
"Mozilla/5.0 (Mobile; Windows Phone 8.1; Android 4.0; ARM; Trident/7.0; Touch; rv:11.0; IEMobile/11.0; NOKIA; Lumia 720) like iPhone OS 7_0_3 Mac OS X AppleWebKit/537 (KHTML, like Gecko) Mobile Safari/537"
Here is the UA string for MS devices
https://msdn.microsoft.com/en-us/library/ie/hh869301%28v=vs.85%29.aspx
According to the README.md your package supports Python 2.5+ but the classifiers says only Python 3.
This misleads software that is interpreting the setup.py
into not building the full compliment of packages that it could.
Hey,
Pip lists httpagentparser as having version number '-1.7.2-' (including the dashes). This means you have to do the slightly weird 'pip install httpagentparser==-1.7.2-'
the following user-agent string causes an error:
>>> httpagentparser.detect(u'Sogou Mobile Spider1.0 for iPhone Android and Mozilla/5.0')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "httpagentparser/__init__.py", line 292, in detect
if detector.detect(agent, result):
File "httpagentparser/__init__.py", line 68, in detect
version = self.getVersion(agent)
File "httpagentparser/__init__.py", line 254, in getVersion
return version.replace('_', '.')
UnboundLocalError: local variable 'version' referenced before assignment
What I have :
"Mozilla/5.0 (X11; Linux x86_64; rv:10.0) Gecko/20100101 Firefox/10.0 (Chrome)"
What httpagentparser tells me :
{'bot': False,
'browser': {'name': 'Chrome', 'version': 'Mozilla/5.0'},
'os': {'name': 'Linux'},
'platform': {'name': 'Linux', 'version': None}}
Note that except the browser being Chrome, the version is wrong too.
What internet tells me :
Mainly Firefox but I'm not sur it corresponds to a real vendor UA, but it seems we can find clients using this UA...
Found this iPad UA string in my server logs, but httpagentparser.detect() doesn't give an "os" field:
>>> httpagentparser.detect('Mozilla/5.0 (iPad; U; CPU OS 4_3_5 like Mac OS X; de-de) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8L1 Safari/6533.18.5')
{'flavor': {'version': 'X', 'name': 'MacOS'}, 'browser': {'version': '5.0.2', 'name': 'Safari'}}
Should this be fixed in the parser, or should I fall back to using "flavor" as OS?
These user agents parse fine:
Opera/9.20 (Windows NT 6.0; U; en), Opera 9, Windows Vista
Opera/9.00 (Windows NT 5.1; U; en), Opera 9, Windows XP
These fail to parse the version correctly, returning something like "Opera Mozilla/4.0" for browser:
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; en) Opera 8.50
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; en) Opera 8.0
Mozilla/4.0 (compatible; MSIE 6.0; MSIE 5.5; Windows NT 5.1) Opera 7.02 [en]
This one fails to detect the browser altogether:
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.5) Gecko/20060127 Netscape/8.1
The User agent is:
Mozilla/5.0 (iPad; CPU OS 6_0_1 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Mobile/10A523 [FBAN/FBIOS;FBAV/5.3;FBBV/89182;FBDV/iPad3,1;FBMD/iPad;FBSN/iPhone OS;FBSV/6.0.1;FBSS/2; FBCR/;FBID/tablet;FBLC/en_US]
It is recognized as:
{'flavor': {'version': 'X) AppleWebKit/536.26 (KHTML, like Gecko) Mobile/10A523 [FBAN/FBIOS', 'name': 'MacOS'}, 'dist': {'version': 'X) AppleWebKit/536.26 (KHTML, like Gecko) Mobile/10A523 [FBAN/FBIOS', 'name': 'IPhone'}}
While the proper parsing from Safari in the same device reads:
{'flavor': {'version': 'X', 'name': 'MacOS'}, 'dist': {'version': 'X', 'name': 'IPad'}, 'browser': {'version': '6.0', 'name': 'Safari'}}
As you can see the dist name is wrongly parsed as "IPhone"
Hello! Setuptools removes previously deprecated test
command, see https://setuptools.pypa.io/en/stable/history.html#v72-0-0 and pypa/setuptools#931
With a new version of setuptools installation fails with ModuleNotFoundError: No module named 'setuptools.command.test'
running in AppEngine (Python 2.7?), hitting the site with OSX 10.6.6 in both Firefox and Chrome an attempt to decode the OS version number throws the error below (from AppEngine log)
using HTTPAgentParser 0.83
Let me know if theres anything else I can grab to help narrow this down...
500 5ms 0cpu_ms 0kb Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_6) AppleWebKit/534.24 (KHTML, like Gecko) Chrome/11.0.696.3 Safari/534.24,gzip(gfe)
220.255.4.30 - - [15/Mar/2011:00:07:52 -0700] "GET /logger.js?i=83&sn=http%3A//blog.offbeatmammal.com/samples/jserr/jserr.html&fl=undefined&ln=undefined&err=%5Bobject%20Event%5D&ui=4E69BF15-0519-4B7B-9C0B-4A1CDD1563DE HTTP/1.1" 500 405 "http://blog.offbeatmammal.com/samples/jserr/jserr.html" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_6) AppleWebKit/534.24 (KHTML, like Gecko) Chrome/11.0.696.3 Safari/534.24,gzip(gfe)" "jserrlog.appspot.com" ms=6 cpu_ms=0 api_cpu_ms=0 cpm_usd=0.000124
E 2011-03-15 00:07:52.898
'version'
Traceback (most recent call last):
File "/base/python_runtime/python_lib/versions/1/google/appengine/ext/webapp/init.py", line 515, in call
handler.get(*groups)
File "/base/data/home/apps/jserrlog/1.348961542918219578/logger.py", line 31, in get
QOSVer = httpagentparser.detect(QUA)['os']['version']
KeyError: 'version'
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.10240
We might want to check for Edge before checking for Chrome as with the above agent, we think that the browser is Chrome.
It should be great to see the version in code in order to compare with current version installed in any project
Please include a reference to the license for the project (PyPi says its MIT) in the source somewhere.
This will keep corporate overlords happy, Thanks.
In [3]: httpagentparser.detect('Mozilla/5.0 (Android 6.0.1; Mobile; rv:63.0) Gecko/63.0 Firefox/63.0')
Out[3]:
{'bot': False,
'browser': {'name': 'AndroidBrowser'},
'dist': {'name': 'Android', 'version': '6.0.1'},
'platform': {'name': 'Android', 'version': '6.0.1'}}```
It would be neat if httpagentparser would detect BlackBerry browsers.
In some server logs I found the following UA strings containing BlackBerry:
"BlackBerry8310/4.5.0.174 Profile/MIDP-2.0 Configuration/CLDC-1.1 VendorID/124"
"BlackBerry8310/4.5.0.69 Profile/MIDP-2.0 Configuration/CLDC-1.1 VendorID/114"
"BlackBerry8520/4.6.1.314 Profile/MIDP-2.0 Configuration/CLDC-1.1 VendorID/124"
"BlackBerry8900/4.6.1.310 Profile/MIDP-2.0 Configuration/CLDC-1.1 VendorID/114"
"BlackBerry8900/5.0.0.1036 Profile/MIDP-2.1 Configuration/CLDC-1.1 VendorID/124"
"BlackBerry8900/5.0.0.681 Profile/MIDP-2.1 Configuration/CLDC-1.1 VendorID/124"
"BlackBerry9000/4.6.0.303 Profile/MIDP-2.0 Configuration/CLDC-1.1 VendorID/114"
"BlackBerry9000/5.0.0.1036 Profile/MIDP-2.1 Configuration/CLDC-1.1 VendorID/124"
"BlackBerry9300/5.0.0.794 Profile/MIDP-2.1 Configuration/CLDC-1.1 VendorID/114"
"BlackBerry9500/4.7.0.78 Profile/MIDP-2.0 Configuration/CLDC-1.1 VendorID/124"
"BlackBerry9500/5.0.0.841 Profile/MIDP-2.1 Configuration/CLDC-1.1 VendorID/124"
"BlackBerry9520/5.0.0.1077 Profile/MIDP-2.1 Configuration/CLDC-1.1 VendorID/124"
"BlackBerry9700/5.0.0.344 Profile/MIDP-2.1 Configuration/CLDC-1.1 VendorID/124"
"BlackBerry9700/5.0.0.442 Profile/MIDP-2.1 Configuration/CLDC-1.1 VendorID/612"
"BlackBerry9700/5.0.0.593 Profile/MIDP-2.1 Configuration/CLDC-1.1 VendorID/114"
"BlackBerry9700/5.0.0.593 Profile/MIDP-2.1 Configuration/CLDC-1.1 VendorID/114 Webwasher/6.8.7"
"BlackBerry9700/5.0.0.593 Profile/MIDP-2.1 Configuration/CLDC-1.1 VendorID/604"
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0) BlackBerry8700/4.1.0 Profile/MIDP-2.0 Configuration/CLDC-1.1 VendorID/100"
"Mozilla/5.0 (BlackBerry; U; BlackBerry 9700; de) AppleWebKit/534.8+ (KHTML, like Gecko) Version/6.0.0.448 Mobile Safari/534.8+"
"Mozilla/5.0 (BlackBerry; U; BlackBerry 9700; de) AppleWebKit/534.8+ (KHTML, like Gecko) Version/6.0.0.668 Mobile Safari/534.8+"
"Mozilla/5.0 (BlackBerry; U; BlackBerry 9700; es) AppleWebKit/534.8+ (KHTML, like Gecko) Version/6.0.0.344 Mobile Safari/534.8+"
"Mozilla/5.0 (BlackBerry; U; BlackBerry 9780; de) AppleWebKit/534.8+ (KHTML, like Gecko) Version/6.0.0.546 Mobile Safari/534.8+"
"Mozilla/5.0 (BlackBerry; U; BlackBerry 9800; de) AppleWebKit/534.1+ (KHTML, like Gecko) Version/6.0.0.246 Mobile Safari/534.1+"
"Mozilla/5.0 (BlackBerry; U; BlackBerry 9800; de) AppleWebKit/534.1+ (KHTML, like Gecko) Version/6.0.0.337 Mobile Safari/534.1+"
looks like for the Opera useragent Opera/9.80 (Windows NT 6.1; U; Edition Next; en) Presto/2.10.229 Version/12.00 we're getting Opera v9.80 reported, not Version 12... not sure if it's an Opera or httpagentparser issue...
For example I would like to know all the possible values of the object that is returned by the detect()
. It will always going to have the os
, browser
?
It would be very helpful if you could tag releases as well. This would enable distributions who want to run your tests to fetch the package from GitHub instead of Pypi, where the tests are excluded.
Thanks
Hello!
Do you plan add support mobile OS's - like iOS, Android....?
Found this curiosity in the logs:
Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0; MSIE; Maxthon/4.1.3.5000)
Output:
{'browser': {'name': 'Microsoft Internet Explorer'},
'os': {'name': 'Windows', 'version': '7'},
'platform': {'name': 'Windows', 'version': '7'}}
I don't know much about Maxthon, but the UA says Trident/7.0 rv:11.0, so it looks like something IE11-powered.
(On related note, I also didn't expect detect()
to return something that has ['browser']
but doesn't have ['browser']['version']
.)
Hey,
I'm using httpagentparser
in my productive code on logged user agents, in order to create some platform- and browser-analysis.
One of the users was logged using
Mozilla/5.0 (iPhone; CPU iPhone OS 16_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 LightSpeed [FBAN/MessengerLiteForiOS;FBAV/403.1.0.38.106;FBBV/462753247;FBDV/iPhone15,3;FBMD/iPhone;FBSN/iOS;FBSV/16.4;FBSS/3;FBCR/;FBID/phone;FBLC/en;FBOP/0]
which yields no browser
key in the resulting dictionary from httpagentparser.detect(line)
. What's your recommendation to handle this?
{'platform': {'name': 'iOS', 'version': '16.4'}, 'os': {'name': 'iOS'}, 'bot': False, 'dist': {'name': 'iPhone', 'version': '16.4'}}
Hei Shon,
First of all, thanks for sharing this! I was looking for an agent parser, and found out your lib in python.org.
I don't know if you are aware of this or not, but I was running some tests and found some inconsistent parsing on the following user-agent:
import httpagentparser
s = "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/534.24 (KHTML, like Gecko) Chrome/11.0.696.60 Safari/534.24"
print httpagentparser.detect(s)
{'os': {'version': 'NT 5.1) AppleWebKit/534.24 (KHTML, like Gecko) Chrome/11.0.696.60 Safari/534.24', 'name': 'Windows'}, 'browser': {'version': '11.0.696.60', 'name': 'Chrome'}}
My computer is running Windows XP SP3, using Chrome 11.0.696.60. All other tests (Linux and Mac) went ok, just so you know.
I took the liberty to write a patch for this, so I pulling it to your code later on.
Thanks,
Mozilla/5.0 (iPhone; CPU iPhone OS 6_0_1 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Mobile/10A523 [FBAN/FBIOS;FBAV/5.1;FBBV/68414;FBDV/iPho
{'dist': {'name': 'IPhone',
'version': 'X) AppleWebKit/536.26 (KHTML, like Gecko) Mobile/10A523 [FBAN/FBIOS'},
'flavor': {'name': 'MacOS',
'version': 'X) AppleWebKit/536.26 (KHTML, like Gecko) Mobile/10A523 [FBAN/FBIOS'}}
Howdy,
first, thanks for the parser!
I found out that Icecat is not supported. The agent string can be e.g. "Mozilla/5.0 (X11; Linux x86_64; rv:7.0.1) Gecko/20111106 IceCat/7.0.1".
Best regards
Alex
Hi,
When I try it with the user agent
Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 10.0; WOW64; Trident/7.0; .NET4.0C; .NET4.0E; .NET CLR 2.0.50727; .NET CLR 3.0.30729; .NET CLR 3.5.30729; Microsoft Outlook 16.0.5257; ms-office; MSOffice 16)
Instead of the correct output MS Office 16 (user agent when Outlook load a external image) , I get the result: Microsoft Internet Explorer 7.0
Do you know why ?
Is it possible to add support for the Kindle Fire devices
Fire: Mozilla/5.0 (Linux; U; en-us; KFOT Build/IML74K) AppleWebKit/535.19 (KHTML, like Gecko) Silk/2.2 Safari/535.19 Silk-Accelerated=true
Fire HD: Mozilla/5.0 (Linux; U; en-us; KFTT Build/IML74K) AppleWebKit/535.19 (KHTML, like Gecko) Silk/2.0 Safari/535.19 Silk-Accelerated=true
Fire HD 8.9 WiFi: Mozilla/5.0 (Linux; U; en-us; KFJWI Build/IML74K) AppleWebKit/535.19 (KHTML, like Gecko) Silk/2.2 Safari/535.19 Silk-Accelerated=true
Fire HD 8.9 WAN: Mozilla/5.0 (Linux; U; en-us; KFJWA Build/IML74K) AppleWebKit/535.19 (KHTML, like Gecko) Silk/2.2 Safari/535.19 Silk-Accelerated=true
the Silk version number seems to vary between 2.0 and 2.2 at the moment, and the Build has varied, but "Silk-Accelerated" seems to be a common factor (true means it goes via EC2, false means it's going direct with no acceleration)
Does httpagentparser yet support IE11 and Windows 8.1?
Here's a user-agent string I grabbed from my install of 8.1:
Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0) like Gecko
https://pypi.python.org/pypi/requests is sending a custom user agent string, including the its version, version of python, e.g.: python-requests/2.7.0 CPython/2.7.10 Darwin/14.3.0
It would be nice if httpagentparser recognize the most common non-browser user agents, at least the python one :)
Because `info.get('browser',{}).get('name', 'unkown') is gross in python :)
This could be done as
detect(full=true)
or (verbose=True)
Holler if you like any of these / want a PR.
Here is the user agent:
Mozilla/5.0 (Windows Phone 10.0; Android 4.2.1; NOKIA; Lumia 920) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2486.0 Mobile Safari/537.36 Edge/13.10586
init.py L313 s/print "detector name: ", detector.name/print("detector name: ", detector.name)/
and then, yop you are py3 compliant at my experience. (I have not rerun your unittest though)
With this user agent "AppleCoreMedia/1.0.0.10B329 (iPad; U; CPU OS 6_1_3 like Mac OS X; en_us)" this variable look_for = 'iPad; CPU OS' in the line 436 is not being triggered.
While other iPads missing the U; like this "Mozilla/5.0 (iPad; CPU OS 7_1 like Mac OS X) AppleWebKit/537.51.2 (KHTML, like Gecko) Version/7.0 Mobile/11D167 Safari/9537.53" are being detected correctly.
I manually looked through some logs and feed it into httpagendparser
and found several wrongly identified user agents, including high profiles google bot:
>>> httpagentparser.detect("Mozilla/5.0 (compatible; AhrefsBot/6.1; +http://ahrefs.com/robot/)")
{'platform': {'name': None, 'version': None}}
>>> httpagentparser.detect("Mozilla/5.0 (Linux; Android 6.0.1; Nexus 5X Build/MMB29P) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.96 Mobile Safari/537.36 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)")
{'platform': {'name': 'Android', 'version': '6.0.1'}, 'os': {'name': 'Linux'}, 'bot': False, 'dist': {'name': 'Android', 'version': '6.0.1'}, 'browser': {'name': 'Chrome', 'version': '41.0.2272.96'}}
>>> httpagentparser.detect("Mozilla/5.0 (X11; U; Linux Core i7-4980HQ; de; rv:32.0; compatible; JobboerseBot; http://www.jobboerse.com/bot.htm) Gecko/20100101 Firefox/38.0")
{'platform': {'name': 'Linux', 'version': None}, 'os': {'name': 'Linux'}, 'bot': False, 'browser': {'name': 'Firefox', 'version': '38.0'}}
>>> httpagentparser.detect("crawler_eb_germany")
{'platform': {'name': None, 'version': None}}
>>> httpagentparser.detect("Mozilla/5.0 (compatible; Qwantify/Bleriot/1.1; +https://help.qwant.com/bot)")
{'platform': {'name': None, 'version': None}}
>>> httpagentparser.detect("Mozilla/5.0 (compatible; SemrushBot/6~bl; +http://www.semrush.com/bot.html)")
{'platform': {'name': None, 'version': None}}
>>> httpagentparser.detect("Mozilla/5.0 (compatible; AhrefsBot/6.1; +http://ahrefs.com/robot/)")
{'platform': {'name': None, 'version': None}}
>>> httpagentparser.detect("ZoominfoBot (zoominfobot at zoominfo dot com)")
{'platform': {'name': None, 'version': None}}
Looks like it's not a fan of ChromeOS at the moment
Mozilla/5.0 (X11; CrOS i686 0.0.0) AppleWebKit/534.24 (KHTML, like Gecko) Chrome/11.0.696.27 Safari/534.24,gzip(gfe)
I'm going to have to learn how to submit these changes myself aren't I :)
"Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.97 Safari/537.22"
detect gives following:
{'os': {'version': '7', 'name': 'Windows'}, 'browser': {'version': 'Mozilla/5.0', 'name': 'Chrome'}}
but the Chrome version is '25.0.1364.97' ...
I've encountered an exception 'IndexError: list index out of range' for strange looking useragent but which came from real access logs:
httpagentparser.detect('U2FsdGVkX1+5L0CpGMQohbnvtzmODt2R90PGcmXwMt57gT+ESJFNzBwF7fpA/Gcw9UiEcsdP0U0G59A/FZT0FJZwvXy1UxNSYx/rct9YmQK1cYYFxRhIZjxFVT0SN1oncZ3TJfcbDl2EaSS7y5dXr/4lNC6Nue/5eY2YxB/PagNdHBZrQljNijjZ1q0xKn+02cUAvfLowYnPzmdXXMQbGI9z2vlxf+T5OScrQnfZeqOtfotYBKTueiCrOSkbLmH0bF25eO1y5cAQqOWb9PUw9Q==')
The same exception rises for 'CrOS' useragent:
print httpagentparser.detect('CrOS')
Traceback (most recent call last):
File "", line 1, in
File "/usr/local/lib/python2.7/dist-packages/httpagentparser/init.py", line 343, in detect
if detector.detect(agent, result):
File "/usr/local/lib/python2.7/dist-packages/httpagentparser/init.py", line 70, in detect
version = self.getVersion(agent)
File "/usr/local/lib/python2.7/dist-packages/httpagentparser/init.py", line 293, in getVersion
return agent.split(self.look_for + version_markers[0])[-1].split(version_markers[1])[1].strip()[:-1]
IndexError: list index out of range
I tried to authenticate my website through Facebook using social auth, but in some case I am getting platform as None, which is breaking the functionality of my website.
Browser Used: Chrome
Note: I am unable to provide the Agent string because we were unable to log that.
Kindly help me on that.
First of all, thanks for your great parser.
I'm using it to parse http clients logs from rackspace and reported issue happens with the client information of Jakarta Commons-HttpClient/3.1
.
Any ideas how to solve that?
Currently I am using this decent library to parse user-agents strings.
However, I found some strings that cannot be parsed. I would paste them here,
in case they are useful.
Mozilla/5.0+(X11;+CrOS+i686+2465.163.0)+AppleWebKit/537.1+(KHTML,+like+Gecko)+Chrome/21.0.1180.91+Safari/537.1
Mozilla/5.0+(X11;+CrOS+i686+2268.111.0)+AppleWebKit/536.11+(KHTML,+like+Gecko)+Chrome/20.0.1132.57+Safari/536.11
would be nice to have type hints added to the library
mypy currently complains due to httpagentparser: module is installed, but missing library stubs or py.typed marker
For strings like :
Netscape(5.0 (Windows NT 6.1) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.186 Safari/535.1)
Netscape(5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/534.10 (KHTML, like Gecko) Chrome/8.0.552.237 Safari/534.10)
Netscape(5.0 (Windows NT 6.1) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.186 Safari/535.1)
Netscape(5.0 (Windows NT 6.1) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.112 Safari/535.1)
Netscape(5.0 (Windows NT 6.1) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.112 Safari/535.1)
Netscape(5.0 (Windows NT 6.1) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.112 Safari/535.1)
Simple_parse returning : Netscape ...
Fix Netscape recognition like this :
class Netscape(Browser):
look_for = "Netscape"
#--- if find 'Chrome' - browser type = 'Chrome' ---
def checkWords(self, agent):
unless_list = ["Chrome"]
if self.look_for in agent:
for word in unless_list:
if word in agent:
return False
return True
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.