使用java实现公共后缀提取
我需要提取网址的顶级域,我得到了他的 http://publicsuffix.org/index.html
并且 java 实现位于 http://guava-libraries.googlecode .com
我找不到 任何提取域名的示例
say example..
example.google.com
returns google.com
and bing.bing.bing.com
returns bing.com
都可以告诉我如何通过示例使用该库来实现......
i need to extract the top domain of an url and i got his http://publicsuffix.org/index.html
and the java implementation is in http://guava-libraries.googlecode.com
and i could not find
any example to extract domain name
say example..
example.google.com
returns google.com
and bing.bing.bing.com
returns bing.com
can any one tell me how can i implement using this library with an example....
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在我看来就像 InternetDomainName.topPrivateDomain() 完全符合您的要求。 Guava 维护一个公共后缀列表(基于 publicsuffix.org 上的 Mozilla 列表),它用它来确定主机的公共后缀部分是什么……顶级私有域是公共后缀加上它的第一个子域。
这是一个简单的示例:
运行此代码会打印:
It looks to me like InternetDomainName.topPrivateDomain() does exactly what you want. Guava maintains a list of public suffixes (based on Mozilla's list at publicsuffix.org) that it uses to determine what the public suffix part of the host is... the top private domain is the public suffix plus its first child.
Here's a quick example:
Running this code prints:
我最近实现了一个公共后缀列表 API:
I recently implemented a Public Suffix List API:
编辑:抱歉我有点太快了。我没想到co.jp。英国等。您需要从某处获取可能的 TLD 列表。您还可以查看 http://commons.apache.org/validator/ 来验证顶级域名。
我认为这样的东西应该可以工作:但也许存在一些Java标准函数。
EDIT: Sorry I've been a little too fast. I didn't think of co.jp. co.uk, and so on. You will need to get a list of possible TLDs from somewhere. You could also take a look at http://commons.apache.org/validator/ to validate a TLD.
I think something like this should work: But maybe there exists some Java-Standard Function.