python3 提取主域名
一瓶水,两包豆奶,一个破站*一天。又是徘徊在***之间的一天。
闲的很,这是我未完成的某个工具其中一个函数。
import re
def getWant(url):
reWant = re.compile('\.[a-zA-Z]+')
d = reWant.findall(url)
# 这是阿里云域名后缀大全 我排除了一些太不常见的和中文
white = ['.com', '.net', '.cn', '.info', '.xin', '.club', '.xyz', '.ltd', '.co', '.wang', '.top', '.vip', '.beer',
'.art', '.cloud', '.site', '.shop', '.fun',
'.link', '.online', '.tech', '.ren', '.pro', '.work', '.ink', '.group', '.store', '.pub', '.live', 'wiki',
'video', 'yoga', '.gov', '.org', '.name',
'.cc', '.tv', '.asia', '.me', '.help', 'game', 'games', '.tel', 'hk']
# 这里就是py3的倒序输出list
for i in reversed(d):
if i not in white:
want = i
break
return want