#获取顶级域名
#不可以存在http://
def TopLeverDomain(domain):
DomainSuffix = {'info': None, 'coop': None, 'mil': None,
'int': None, 'xxx': None, 'pro': None, 'aero': None, 'idv': None,
'biz': None, 'edu': None, 'org': None, 'net': None, 'gov': None,
'com': None, 'museum': None, 'name': None}
Result = []
if domain.count('.') == 1:
return domain
PointSplitResult = domain.split('.')
if len(filter(lambda x: not x.isdigit(), PointSplitResult)) == 0:
return domain
if DomainSuffix.has_key(PointSplitResult[-1].lower()):
Result = PointSplitResult[-2:]
else:
if DomainSuffix.has_key(PointSplitResult[-2].lower()):
Result = PointSplitResult[-3:]
else:
Result = PointSplitResult[-2:]
return '.'.join(Result)
以上为py获取顶级域名的方法