【问题标题】:Parsing user agent OS Version is empty?解析用户代理操作系统版本为空?
【发布时间】:2015-01-07 06:14:01
【问题描述】:

对于下面的用户代理,操作系统版本似乎是空的,为什么它没有价值?不会有任何价值吗?

User Agent = Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.22+ (KHTML, like Gecko) Chromium/17.0.963.56 Chrome/17.0.963.56 Safari/535.22+ Debian/7.0 (3.4.2-2.1) Epiphany/3.4.2 

结果:

ua_family = Epiphany, os_family = Debian, os_version = , device_family = Other, device = Desktop 

here解析用户代理。

【问题讨论】:

  • 如果你有这些信息,你会怎么处理?
  • 我正在尝试使用该信息识别设备。

标签: linux parsing operating-system debian user-agent


【解决方案1】:

该库的main source file 非常易于阅读——看起来它对 Linux 发行版了解不多(除非它们也恰好是某种移动操作系统):

MOBILE_DEVICE_FAMILIES = (
    ...
)

PC_OS_FAMILIES = (                   <-- no Linux! :(
    'Windows 95',
    'Windows 98',
    'Windows ME',
    'Solaris',
)

MOBILE_OS_FAMILIES = (
    ...
)

MOBILE_BROWSER_FAMILIES = (
    ...
)

TABLET_DEVICE_FAMILIES = (
    ...
)

TOUCH_CAPABLE_OS_FAMILIES = (
    ...
)

TOUCH_CAPABLE_DEVICE_FAMILIES = (
    ...
)

如果您只关心从您的 UA 行中获取操作系统信息,那么 UA 行有几个部分由“/”分隔:

Mozilla                                  <-- Note: no "User Agent = "
5.0 (X11; Linux x86_64) AppleWebKit
535.22+ (KHTML, like Gecko) Chromium
17.0.963.56 Chrome
17.0.963.56 Safari
535.22+ Debian
7.0 (3.4.2-2.1) Epiphany
3.4.2

您基本上想识别(X11; Linux x86_64)Debian7.0 (3.4.2-2.1) Epiphany3.4.2 部分,它们告诉您“这是基于 Debian 7.0 的 x86_64 上的 Linux 发行版,内核版本为 3.4.2-2.1 。”

您总是可以创建一个拉取请求并向其中添加一些 Linux 版本!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-03-27
    • 2012-02-05
    • 1970-01-01
    • 2020-07-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多