Focus on useragent analysing.
UA Detector 是一个用于分析 User-Agent 字符串的程序包,能从中识别出操作系统、浏览器、客户端,以及设备品牌(仅移动设备)。
通过 npm 全局安装:
npm install uadetector -g
安装成功后,可以通过此命令查看版本号:
uadetect -v
分析设备品牌:
uadetect "an useragent string" -devicebrand
分析操作系统:
uadetect "an useragent string" -os
分析浏览器:
uadetect "an useragent string" -browser
分析客户端:
uadetect "an useragent string" -client
分析全部:
uadetect "an useragent string" -devicebrand -os -browser -client
结果默认以 JSON 字符串输出,但也可以通过 output-format
参数指定输出格式:
uadetect "an useragent string" -os -output-format "%name|%version"
在需要使用本程序包的项目中安装为依赖:
npm install uadetector
调用接口进行分析:
const detector = {
os: require('uadetector/os'),
deviceBrand: require('uadetector/device-brand'),
browser: require('uadetector/browser'),
client: require('uadetector/client')
};
const USER_AGENT = 'an useragent string';
console.dir(detector.os.exec(USER_AGENT));
console.dir(detector.deviceBrand.exec(USER_AGENT));
console.dir(detector.browser.exec(USER_AGENT));
console.dir(detector.client.exec(USER_AGENT));
支持以下操作系统的识别:
Android、BlackBerry、ChromeOS、FreeBSD、Linux、OpenHarmony、Symbian、Windows、Windows CE、Windows Mobile、Windows Phone、YunOS、iOS、macOS(Mac OS X)
支持以下浏览器(内核)的识别:
Chrome、Chrome Mobile、Edge、Firefox、IE、IE Mobile、Mobile Firefox、Mobile Safari、Opera (Presto)、Opera Mini、Opera Mobile (Presto)、Safari、Webkit (Mobile)、Webkit (PC)
同时也支持以下爬虫的识别:
Baidu Spider、Googlebot、Bingbot、DingTalkBot、SogouSpider、YisouSpider、Sosospider、360Spider
支持以下客户端的识别:
2345 手机浏览器(Mobile)、2345 浏览器 (PC)、360 浏览器 (Mobile)、Edge (Mobile)、Edge (PC)、Electron、GreenBrowser、HeyTap 浏览器、MIUI 浏览器、Opera (Blink)、Opera Mobile (Blink)、Oppo 浏览器、QQ (Mobile)、QQ 浏览器 (Mobile)、QQ 浏览器 (PC)、Qzone (Mobile)、UC 浏览器 (Mobile)、UC 浏览器 (PC)、Vivo 浏览器、uni-app、三星浏览器、世界之窗、企业微信 (Mobile)、企业微信 (PC)、傲游 (Mobile)、傲游 (PC)、华为浏览器、夸克浏览器、小白浏览器、微信 (Mobile)、微信 (PC)、搜狗浏览器 (Mobile)、搜狗浏览器 (PC)、新浪微博 (Mobile)、欧朋 (Mobile)、猎豹浏览器 (Mobile)、猎豹浏览器 (PC)、百度 (Mobile)、百度浏览器 (Mobile)、百度浏览器 (PC)、联想浏览器、钉钉 (Mobile)
当无法命中以上客户端的识别规则时,将回退至浏览器识别。
注意:
支持以下设备品牌的识别:
360、Google、HTC、LG、OPPO、Realme、TCL、iPad、iPhone、iPod、realme、vivo、一加、三星、中兴、乐丰、乐视、亿通、优学派、优购、传音、作业帮、华为、华硕、坚果、夏新、天语、学而思、宇飞来、小度、小米、小辣椒、康佳、快易典、摩托罗拉、朵唯、欧沃、比亚迪、波导、海信、海尔、糖果、索尼、纽曼、美图、联想、诺基亚 (Android)、诺基亚/Lumia、读书郎、酷比、酷派、金立、锤子、飞利浦、魅族
注意:
erazer
关键词。browser-core
改名为 browser
。browser
改名为 client
。