python怎么判断某个域名是顶级域名还是二级域名

发布网友 发布时间:2022-04-24 00:42

我来回答

4个回答

热心网友 时间:2022-05-10 23:43

使用如下代码判断:

#!/usr/bin/env python
import re
def getDomain(s):
 res = s
 domainS = [".com",".cn",".com.cn",".gov",".net",".e.cn",".net.cn",".org.cn",".co.jp",".gov.cn",".co.uk","ac.cn",".e",".tv",".info",".ac",".ag",".am",".at",".be",".biz",".bz",".cc",".de",".es",".eu",".fm",".gs",".hk",".in",".info",".io",".it",".jp",".la",".md",".ms",".name",".nl",".nu",".org",".pl",".ru",".sc",".se",".sg",".sh",".tc",".tk",".tv",".tw",".us",".co",".uk",".vc",".vg",".ws",".il",".li",".nz"]
 for l in domainS:
 regex = re.compile(r'[0-9a-zA-Z_-]+'+l+'$')
 m = regex.findall(s)
 if len(m) > 0:
 return m[0]
else:
pass
 return res

if"__main__":
 print getDomain("www.baidu.com")

热心网友 时间:2022-05-11 01:01

比如:.com 这是百度的顶级域名

zhidao.baidu.com 这是二级域名

www.baidu.com这也是二级域名

.zhidao.baidu.com 这是*域名

*.baidu.com 这是泛域名

习惯上这样区分,一般不称谓一级域名。个别人说指的一级域名就是顶级域名。

热心网友 时间:2022-05-11 02:35

www.QQ.com是顶级 lol.QQ.com 就是2级。

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com