我的函数有问题,应该从域中删除tld。若域中有一些子域,它将正常工作。例如:
输入:asdf.xyz.example.com
输出:asdf.xyz.example
问题是当域没有任何子域时,域前面有点
输入:example.com
输出:.example
这是我的代码:
res = get_tld(domain, as_object=True, fail_silently=True, fix_protocol=True)
domain = '.'.join([res.subdomain, res.domain])
函数get_tld
来自tld library
有人能帮我解决这个问题吗
另一个简单的版本是:
*base, tld = url.split(".")
将TLD放在tld
中,其他所有内容放在base
中。然后你只需要用{通过一个非常简单的字符串操作,这就是您想要的吗
你可以使用过滤。看起来
get_tld
工作正常,但join
不正确相关问题 更多 >
编程相关推荐