寻找 Java 用户代理字符串解析器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1493617/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 13:25:22  来源:igfitidea点击:

Looking for a Java User Agent String Parser

javaparsinguser-agent

提问by Bill

Does anyone know of a great library in java for parsing user agent strings? We have written a custom one, but this seems like a common problem for many people. I would guess there is a good library available somewhere.

有谁知道 java 中用于解析用户代理字符串的优秀库?我们写了一个自定义的,但这对很多人来说似乎是一个常见的问题。我猜想某处有一个很好的图书馆。

For example, the user agent string...

例如,用户代理字符串...

"Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US) AppleWebKit/532.0 (KHTML, like Gecko) Chrome/3.0.195.21 Safari/532.0"

"Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US) AppleWebKit/532.0 (KHTML, like Gecko) Chrome/3.0.195.21 Safari/532.0"

... cryptically announces the arrival of a Windows Vista PC using Chrome on our site.

... 在我们的网站上神秘地宣布使用 Chrome 的 Windows Vista PC 的到来。

I've seen libraries in python and ruby. Anything in java out there?

我见过 python 和 ruby​​ 中的库。java中有什么东西吗?

回答by Esko

As far as I know (and why shouldn't I, it's one of the services company I used to work at provides with its products), detecting user agents when done properly is actually a good business in itself.

据我所知(我为什么不应该这样做,它是我曾经工作过的服务公司之一,提供其产品),在正确完成时检测用户代理本身实际上是一项很好的业务。

There are several free databases such as WURFLcontaining some rudimentary identification patterns for user agents but those mainly focus on for example mobile phones so in the end you may have to keep using the one you've made and just add the capability to import from/export to various related formats related to current state of user agent identification metadata.

有几个免费的数据库,例如WURFL,其中包含一些用于用户代理的基本识别模式,但那些主要集中在例如移动电话上,因此最终您可能不得不继续使用您创建的数据库,并添加从/导入的功能导出到与用户代理标识元数据的当前状态相关的各种相关格式。

If you're not going to steer away from desktop/PC world, you won't have much to worry about though since there's only four major layout engines out there with of course a set of versions with varying capabilities. The four big ones are the one in Trident in IE, Mozilla's Gecko, KDE's WebKit(at least in Safari and Chrome) and Opera's Presto.

如果您不打算远离台式机/PC 世界,那么您就不必担心太多,因为只有四个主要的布局引擎,当然还有一组具有不同功能的版本。四大是IE中的TridentMozilla 的 GeckoKDE 的 WebKit(至少在 Safari 和 Chrome 中)和Opera 的 Presto

回答by before

Yet try a new library that is updated monthly and available in The Central Repository: http://uadetector.sourceforge.net/

然而,尝试一个新的库,它每月更新一次,可在中央存储库中找到http: //uadetector.sourceforge.net/

It is another wrapper for user-agent-string.info, but with a much more solid and tested implementation compared to the other ones.

它是user-agent-string.info 的另一个包装器,但与其他实现相比,它具有更可靠和经过测试的实现。

I'm working on a stable API 1.0 which I want to release at the end of this year. After the release of API 1.0 you don't have to recompile anything. You only switch the uadetector-resources.jar in your applications lib dir. The feature 'updated monthly' means, if you want an integration tested 'UAS data' file, for which you have the guarantee that it runs with the defined core, than this one fit your needs. But if you are not interested in updating a JAR (that is tested by me), then you can use the OnlineUserAgentStringParser with the risk, that the implementation doesn't fit to run with the automatically downloaded XML. I'm not interested in releasing more 'uadetector-core' bundles as needed, especially when the API in version 1.0 is released.

我正在开发一个稳定的 API 1.0,我想在今年年底发布。API 1.0 发布后,您无需重新编译任何内容。您只需在应用程序库目录中切换 uadetector-resources.jar。“每月更新”功能意味着,如果您想要一个经过集成测试的“UAS 数据”文件,您可以保证它与定义的核心一起运行,那么这个文件适合您的需求。但是,如果您对更新 JAR(由我测试过)不感兴趣,那么您可以使用 OnlineUserAgentStringParser,但存在风险,即该实现不适合使用自动下载的 XML 运行。我对根据需要发布更多“uadetector-core”包不感兴趣,尤其是在发布 1.0 版 API 时。

Another solution for a client might be that he maintains the 'UAS data' for it's own, when he works with the OnlineUserAgentStringParser and customize the properties file to set the right URL.

客户的另一个解决方案可能是,当他使用 OnlineUserAgentStringParser 并自定义属性文件以设置正确的 URL 时,他为其自己维护“UAS 数据”。