# ua-device 2.0
解析user-agent的python包,可以获取到系统、浏览器内核、浏览器、设备信息。
## 重要提示:2.0版本重大变更
⚠️ 2.0版本进行了完全重构,与1.x版本不兼容。主要变更:
1. **简化代码结构**
- 删除了大量历史设备和过时浏览器的识别规则
- 重构了核心解析逻辑,提升执行效率
- 代码结构更清晰,便于维护和扩展
2. **功能优化**
- 优化了浏览器内核识别逻辑,准确区分Blink和WebKit
- 聚焦于主流设备和浏览器的识别
- 移除了低使用率的特殊规则
3. **性能提升**
- 减少正则表达式的使用
- 优化了匹配算法
- 显著提升解析速度
如果您需要继续使用旧版本的完整功能,请安装1.x版本:
```bash
pip install "uaDevice<2.0"
```
## 特点
* 相比国内外的流行的python包,该模块解析国内复杂的ua信息更加精确
* 已支持鸿蒙系统解析
* 准确识别Blink/WebKit等主流浏览器内核
* 专注于现代浏览器和设备的识别
## 主要功能
### 1. 浏览器引擎识别
* Blink (Chrome、新版Edge等)
* WebKit (Safari等)
* Gecko (Firefox)
* Trident (IE)
* Presto (旧版Opera)
### 2. 浏览器识别
* 主流浏览器:Chrome、Firefox、Safari、Edge等
* 国内浏览器:QQ浏览器、UC浏览器、搜狗浏览器等
* 手机厂商浏览器:MIUI浏览器、华为浏览器、OPPO浏览器等
* 其他常用浏览器:微信内置浏览器、百度App等
### 3. 系统识别
* 桌面系统:Windows、macOS、Linux等
* 移动系统:iOS、Android、Harmony等
### 4. 设备识别
* 设备类型:手机、平板、桌面设备等
* 设备品牌:Apple、Samsung、Huawei等
* 具体机型识别
## 解析成功率
供参考(以10000个真实请求ua测试):
* 浏览器:98%
* 系统: 99%
* 内核: 98%
* 设备类型: 100%
* 设备型号:86%
* 厂商信息:93%
## 安装
```bash
pip install -U uaDevice
```
## 使用
```python
import uaDevice
# Chrome浏览器示例
ua = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36'
info = uaDevice.parseUA(ua)
# 输出结果示例
print(f"系统: {info['os']['name']} {info['os']['version']['original']}") # Windows 10.0
print(f"浏览器: {info['browser']['name']} {info['browser']['version']['original']}") # Chrome 91.0.4472.124
print(f"内核: {info['engine']['name']}") # Blink
print(f"设备类型: {info['device']['type']}") # desktop
print(f"设备型号: {info['device']['model']}") # PC
print(f"制造商: {info['device']['manufacturer']}") # Unknown
# 安卓移动端示例
ua = 'Mozilla/5.0 (Linux; Android 13; SM-S918B) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Mobile Safari/537.36'
info = uaDevice.parseUA(ua)
# 输出结果示例
print(f"系统: {info['os']['name']} {info['os']['version']['original']}") # Android 13
print(f"浏览器: {info['browser']['name']} {info['browser']['version']['original']}") # Chrome 114.0.0.0
print(f"内核: {info['engine']['name']}") # Blink
print(f"设备类型: {info['device']['type']}") # mobile
print(f"设备型号: {info['device']['model']}") # SM-S918B
print(f"制造商: {info['device']['manufacturer']}") # Samsung
```
## 贡献
随着新设备新app等等的上市,ua信息会越来越复杂,该项目需要不断迭代,欢迎提交PR或Issue来完善不支持的ua解析规则。
Raw data
{
"_id": null,
"home_page": "https://github.com/kaivean/python-ua-device",
"name": "uaDevice",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": "ua, user-agent, User Agent, parser, device, os, browser, engine, data analysis, china, \u4e2d\u56fd, \u56fd\u5185",
"author": "kaivean",
"author_email": "kaivean@outlook.com",
"download_url": "https://files.pythonhosted.org/packages/27/1d/ee799b274e471d4c7be680ef44a2d906cc0525761182921b64bd3577a677/uaDevice-2.0.1.tar.gz",
"platform": "any",
"description": "# ua-device 2.0\n\u89e3\u6790user-agent\u7684python\u5305\uff0c\u53ef\u4ee5\u83b7\u53d6\u5230\u7cfb\u7edf\u3001\u6d4f\u89c8\u5668\u5185\u6838\u3001\u6d4f\u89c8\u5668\u3001\u8bbe\u5907\u4fe1\u606f\u3002\n\n## \u91cd\u8981\u63d0\u793a\uff1a2.0\u7248\u672c\u91cd\u5927\u53d8\u66f4\n\u26a0\ufe0f 2.0\u7248\u672c\u8fdb\u884c\u4e86\u5b8c\u5168\u91cd\u6784\uff0c\u4e0e1.x\u7248\u672c\u4e0d\u517c\u5bb9\u3002\u4e3b\u8981\u53d8\u66f4\uff1a\n\n1. **\u7b80\u5316\u4ee3\u7801\u7ed3\u6784**\n - \u5220\u9664\u4e86\u5927\u91cf\u5386\u53f2\u8bbe\u5907\u548c\u8fc7\u65f6\u6d4f\u89c8\u5668\u7684\u8bc6\u522b\u89c4\u5219\n - \u91cd\u6784\u4e86\u6838\u5fc3\u89e3\u6790\u903b\u8f91\uff0c\u63d0\u5347\u6267\u884c\u6548\u7387\n - \u4ee3\u7801\u7ed3\u6784\u66f4\u6e05\u6670\uff0c\u4fbf\u4e8e\u7ef4\u62a4\u548c\u6269\u5c55\n\n2. **\u529f\u80fd\u4f18\u5316**\n - \u4f18\u5316\u4e86\u6d4f\u89c8\u5668\u5185\u6838\u8bc6\u522b\u903b\u8f91\uff0c\u51c6\u786e\u533a\u5206Blink\u548cWebKit\n - \u805a\u7126\u4e8e\u4e3b\u6d41\u8bbe\u5907\u548c\u6d4f\u89c8\u5668\u7684\u8bc6\u522b\n - \u79fb\u9664\u4e86\u4f4e\u4f7f\u7528\u7387\u7684\u7279\u6b8a\u89c4\u5219\n\n3. **\u6027\u80fd\u63d0\u5347**\n - \u51cf\u5c11\u6b63\u5219\u8868\u8fbe\u5f0f\u7684\u4f7f\u7528\n - \u4f18\u5316\u4e86\u5339\u914d\u7b97\u6cd5\n - \u663e\u8457\u63d0\u5347\u89e3\u6790\u901f\u5ea6\n\n\u5982\u679c\u60a8\u9700\u8981\u7ee7\u7eed\u4f7f\u7528\u65e7\u7248\u672c\u7684\u5b8c\u6574\u529f\u80fd\uff0c\u8bf7\u5b89\u88c51.x\u7248\u672c\uff1a\n\n```bash\npip install \"uaDevice<2.0\"\n```\n\n## \u7279\u70b9\n* \u76f8\u6bd4\u56fd\u5185\u5916\u7684\u6d41\u884c\u7684python\u5305\uff0c\u8be5\u6a21\u5757\u89e3\u6790\u56fd\u5185\u590d\u6742\u7684ua\u4fe1\u606f\u66f4\u52a0\u7cbe\u786e\n* \u5df2\u652f\u6301\u9e3f\u8499\u7cfb\u7edf\u89e3\u6790\n* \u51c6\u786e\u8bc6\u522bBlink/WebKit\u7b49\u4e3b\u6d41\u6d4f\u89c8\u5668\u5185\u6838\n* \u4e13\u6ce8\u4e8e\u73b0\u4ee3\u6d4f\u89c8\u5668\u548c\u8bbe\u5907\u7684\u8bc6\u522b\n\n## \u4e3b\u8981\u529f\u80fd\n\n### 1. \u6d4f\u89c8\u5668\u5f15\u64ce\u8bc6\u522b\n* Blink (Chrome\u3001\u65b0\u7248Edge\u7b49)\n* WebKit (Safari\u7b49)\n* Gecko (Firefox)\n* Trident (IE)\n* Presto (\u65e7\u7248Opera)\n\n### 2. \u6d4f\u89c8\u5668\u8bc6\u522b\n* \u4e3b\u6d41\u6d4f\u89c8\u5668\uff1aChrome\u3001Firefox\u3001Safari\u3001Edge\u7b49\n* \u56fd\u5185\u6d4f\u89c8\u5668\uff1aQQ\u6d4f\u89c8\u5668\u3001UC\u6d4f\u89c8\u5668\u3001\u641c\u72d7\u6d4f\u89c8\u5668\u7b49\n* \u624b\u673a\u5382\u5546\u6d4f\u89c8\u5668\uff1aMIUI\u6d4f\u89c8\u5668\u3001\u534e\u4e3a\u6d4f\u89c8\u5668\u3001OPPO\u6d4f\u89c8\u5668\u7b49\n* \u5176\u4ed6\u5e38\u7528\u6d4f\u89c8\u5668\uff1a\u5fae\u4fe1\u5185\u7f6e\u6d4f\u89c8\u5668\u3001\u767e\u5ea6App\u7b49\n\n### 3. \u7cfb\u7edf\u8bc6\u522b\n* \u684c\u9762\u7cfb\u7edf\uff1aWindows\u3001macOS\u3001Linux\u7b49\n* \u79fb\u52a8\u7cfb\u7edf\uff1aiOS\u3001Android\u3001Harmony\u7b49\n\n### 4. \u8bbe\u5907\u8bc6\u522b\n* \u8bbe\u5907\u7c7b\u578b\uff1a\u624b\u673a\u3001\u5e73\u677f\u3001\u684c\u9762\u8bbe\u5907\u7b49\n* \u8bbe\u5907\u54c1\u724c\uff1aApple\u3001Samsung\u3001Huawei\u7b49\n* \u5177\u4f53\u673a\u578b\u8bc6\u522b\n\n## \u89e3\u6790\u6210\u529f\u7387\n\u4f9b\u53c2\u8003\uff08\u4ee510000\u4e2a\u771f\u5b9e\u8bf7\u6c42ua\u6d4b\u8bd5\uff09:\n* \u6d4f\u89c8\u5668\uff1a98%\n* \u7cfb\u7edf\uff1a 99%\n* \u5185\u6838\uff1a 98%\n* \u8bbe\u5907\u7c7b\u578b\uff1a 100%\n* \u8bbe\u5907\u578b\u53f7\uff1a86%\n* \u5382\u5546\u4fe1\u606f\uff1a93%\n\n## \u5b89\u88c5\n\n```bash\npip install -U uaDevice\n```\n\n## \u4f7f\u7528\n\n```python\nimport uaDevice\n\n# Chrome\u6d4f\u89c8\u5668\u793a\u4f8b\nua = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36'\ninfo = uaDevice.parseUA(ua)\n\n# \u8f93\u51fa\u7ed3\u679c\u793a\u4f8b\nprint(f\"\u7cfb\u7edf: {info['os']['name']} {info['os']['version']['original']}\") # Windows 10.0\nprint(f\"\u6d4f\u89c8\u5668: {info['browser']['name']} {info['browser']['version']['original']}\") # Chrome 91.0.4472.124\nprint(f\"\u5185\u6838: {info['engine']['name']}\") # Blink\nprint(f\"\u8bbe\u5907\u7c7b\u578b: {info['device']['type']}\") # desktop\nprint(f\"\u8bbe\u5907\u578b\u53f7: {info['device']['model']}\") # PC\nprint(f\"\u5236\u9020\u5546: {info['device']['manufacturer']}\") # Unknown\n\n# \u5b89\u5353\u79fb\u52a8\u7aef\u793a\u4f8b\nua = 'Mozilla/5.0 (Linux; Android 13; SM-S918B) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Mobile Safari/537.36'\ninfo = uaDevice.parseUA(ua)\n\n# \u8f93\u51fa\u7ed3\u679c\u793a\u4f8b\nprint(f\"\u7cfb\u7edf: {info['os']['name']} {info['os']['version']['original']}\") # Android 13\nprint(f\"\u6d4f\u89c8\u5668: {info['browser']['name']} {info['browser']['version']['original']}\") # Chrome 114.0.0.0\nprint(f\"\u5185\u6838: {info['engine']['name']}\") # Blink\nprint(f\"\u8bbe\u5907\u7c7b\u578b: {info['device']['type']}\") # mobile\nprint(f\"\u8bbe\u5907\u578b\u53f7: {info['device']['model']}\") # SM-S918B\nprint(f\"\u5236\u9020\u5546: {info['device']['manufacturer']}\") # Samsung\n```\n\n## \u8d21\u732e\n\u968f\u7740\u65b0\u8bbe\u5907\u65b0app\u7b49\u7b49\u7684\u4e0a\u5e02\uff0cua\u4fe1\u606f\u4f1a\u8d8a\u6765\u8d8a\u590d\u6742\uff0c\u8be5\u9879\u76ee\u9700\u8981\u4e0d\u65ad\u8fed\u4ee3\uff0c\u6b22\u8fce\u63d0\u4ea4PR\u6216Issue\u6765\u5b8c\u5584\u4e0d\u652f\u6301\u7684ua\u89e3\u6790\u89c4\u5219\u3002\n\n\n",
"bugtrack_url": null,
"license": "MIT Licence",
"summary": "User Agent parser, More accurate",
"version": "2.0.1",
"project_urls": {
"Homepage": "https://github.com/kaivean/python-ua-device"
},
"split_keywords": [
"ua",
" user-agent",
" user agent",
" parser",
" device",
" os",
" browser",
" engine",
" data analysis",
" china",
" \u4e2d\u56fd",
" \u56fd\u5185"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "271dee799b274e471d4c7be680ef44a2d906cc0525761182921b64bd3577a677",
"md5": "6bb327c9205cffe362cf0256048ea40d",
"sha256": "85fb9f39d98dc6dd4d01fb02f0cf074648af83dcece488eea030a5f72e31ac41"
},
"downloads": -1,
"filename": "uaDevice-2.0.1.tar.gz",
"has_sig": false,
"md5_digest": "6bb327c9205cffe362cf0256048ea40d",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 12498,
"upload_time": "2024-12-01T08:01:35",
"upload_time_iso_8601": "2024-12-01T08:01:35.709786Z",
"url": "https://files.pythonhosted.org/packages/27/1d/ee799b274e471d4c7be680ef44a2d906cc0525761182921b64bd3577a677/uaDevice-2.0.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-12-01 08:01:35",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "kaivean",
"github_project": "python-ua-device",
"travis_ci": true,
"coveralls": false,
"github_actions": false,
"lcname": "uadevice"
}