OpenResty中使用lua-resty-woothee解析User-Agent
OpenRestyLua大约 962 字项目介绍
lua-resty-woothee
是Woothee
的OpenResty版本
。Woothee
是一个多语言的User-Agent
解析器。
开源地址:https://github.com/woothee/lua-resty-woothee
快速入门
安装依赖
luarocks install lua-resty-woothee
代码示例
local woothee = require "resty.woothee"
-- parse
local r = woothee.parse(ngx.var.http_user_agent)
-- => {"name": "xxx", "category": "xxx", "os": "xxx", "version": "xxx", "vendor": "xxx"}
-- crawler?
local crawler = woothee.is_crawler(ngx.var.http_user_agent)
-- => true
常用方法
result = woothee.parse(ua)
传入User-Agent
字符串,返回Table
类型结果。
crawler = woothee.is_crawler(ua)
判断是否是爬虫,返回布尔类型。
字段解释
{"name":"Chrome","category":"pc","os":"Windows 10","version":"79.0.3945.130","vendor":"Google","os_version":"NT 10.0"}
- name:浏览器名称;
- category:平台类型;
pc
: 电脑smartphone
:智能手机mobilephone
:移动电话appliance
:应用crawler
:爬虫misc
:其他unknown
:未知
- os:操作系统;
- version:浏览器版本号;
- os_version:操作系统版本号;
- vendor:浏览器制造商;
备注
可以根据category
是否为crawler
来判断是否是爬虫,和is_crawler
效果一样。
开源案例
阅读 1055 · 发布于 2020-03-01
————        END        ————
扫描下方二维码关注公众号和小程序↓↓↓

昵称:
随便看看换一批
- PostgreSQL修改数据库拥有者阅读 755
- Windows10访问网页提示找不到服务器IP地址阅读 4744
- PostgreSQL使用\copy命令时报character with byte sequence 0xc3 0xa5 in encoding "UTF8" has no equivalent in encoding "GBK"阅读 3080
- Nginx配置之PHP路径配置阅读 479
- Linux sort命令简单使用阅读 568
- 设计模式之模板方法模式阅读 314
- Android ListView条目点击变色阅读 408
- PostgreSQL下载安装及运行阅读 1019
- Android软键盘遮挡控件阅读 423
- 设计模式之桥接模式阅读 599