url截取域名

XiaoBaiBai · · 878 次点击
``` func getUrl(str string) string{ l := strings.Split(str,".") if l[len(l)-1] =="com" || l[len(l)-1] =="cn"{ if l[len(l)-2]=="com"{ tmp:= l[len(l)-2:] return fmt.Sprintf(".%s.%s",tmp[0],tmp[1]) }else{ tmp:= l[len(l)-1:] return fmt.Sprintf(".%s",tmp[0]) } } } ```
#2
更多评论
``` str := "www.baidu.com.cn" index := strings.Index(str, ".com") sub := str[index:] fmt.Println(sub) ```
#1
这其实是很复杂的问题,baidu.cn.com怎么取喃? https://chromium.googlesource.com/chromium/src/+/refs/heads/main/net/base/registry_controlled_domains/effective_tld_names.dat
#3