python通过urlparse分析处网址中的域名

2022-04-26 00:00:00 分析 域名 网址

给定网址,通过这段python代码可以很容易获取域名信息

"""
皮蛋编程(https://www.pidancode.com)
创建日期:2022/4/24
功能描述:python通过urlparse分析处网址中的域名
"""
import urllib.parse
url = "https://www.pidancode.com"
domain = urllib.parse.urlsplit(url)[1].split(':')[0]
print("The domain name of the url is: ", domain)

输出结果

The domain name of the url is:  www.pidancode.com

相关文章