域名拆分 tld

概念

URL

Universal Resource Locator ,统一资源定位符。

用处:用来标识互联网资源的唯一地址。

本质:提供了互联网上任一资源地址的通用表示方法。

protocol://host:port/path/file.name?parameter

红色部分合称为domain

如:http://baidu.com/index.html  ftp://example/index.pdf

 

https://www.baidu.com

TLD:顶级域——>com

SLD:二级域——>baidu

子域名:——>www

 

用Python的第三方包 tld,拆分域名信息。

from tld import get_tld, get_fld

url = 'http://www.baidu.com'

print(get_fld(url))
# baidu.com

s = get_tld("http://www.baidu.com", as_object=True)
print(s, s.domain, s.subdomain, s.fld)
print(s.parsed_url, s.parsed_url.scheme, s.parsed_url.netloc)

# com baidu www baidu.com
#
SplitResult(scheme='http', netloc='www.baidu.com', path='', query='', fragment='') http www.baidu.com

 

更多方法

 

转载于:https://www.cnblogs.com/ldy-miss/p/10233304.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值