UserAgentUtils 始终提供空浏览器版本

发布于 2024-12-29 02:28:56 字数 578 浏览 3 评论 0原文

我正在使用 UserAgentUtils Java 库在 PDI 转换期间从浏览器的用户代理字符串中提取用户代理详细信息,但无论我做什么,在解析用户代理字符串后我总是从库中返回空版本,即使在我可以清楚地看到字符串中的版本。例如:

String userAgentString = "Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en-US) AppleWebKit/533.3 (KHTML, like Gecko) capybara-webkit Safari/533.3"
UserAgent userAgent = new UserAgent(userAgentString)
userAgent.getBrowserVersion() //always comes back null

两个问题。我没有做正确的事情来从 UserAgentUtils 取回数据(这似乎不是一个错误,因为他们的错误跟踪系统中没有与此相关的问题历史记录)?

或者,是否有另一个 Java 或 JavaScript 库可以用来从用户代理字符串中提取组件信息?两者都可以,因为我可以同样轻松地在该代码所在的 PDI 作业中使用其中任何一个。

I'm using the UserAgentUtils Java library to extract user agent details from the user agent string of browsers during a PDI transform, but no matter what I do I always get back a null version from the library after parsing the user agent string, even when I can clearly see the version in the string. For example:

String userAgentString = "Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en-US) AppleWebKit/533.3 (KHTML, like Gecko) capybara-webkit Safari/533.3"
UserAgent userAgent = new UserAgent(userAgentString)
userAgent.getBrowserVersion() //always comes back null

Two questions. What am I not doing right to get back the data from UserAgentUtils (it doesn't seem to be a bug because there's no history of issues related to this in their bug tracking system)?

Alternatively, is there another Java or JavaScript library I could use to extract the component information from user agent strings? Either one is okay, since I can equally easily use either in the PDI job where this code lives.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

陪我终i 2025-01-05 02:28:56

您是否尝试为 jetty http 客户端请求设置 http 代理值?

我在我的用户定义的java类上执行此操作:

import java.lang.System.*;
...
System.setProperty("http.agent", "my cool crawler, [email protected]");

现在来自kettle的所有http请求都将发送带有此信息的用户代理标头

are you trying to set the http agent value for jetty http client requests?

i do this on my user defined java class:

import java.lang.System.*;
...
System.setProperty("http.agent", "my cool crawler, [email protected]");

now all your http requests from kettle will send user agent header with this info

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文