实例:
from urllib.parse import urlparse
url = 'http://www.baidu.com:80'
_url = urlparse(url)
hostname = _url.hostname
port = _url.port
scheme = _url.scheme
print(f'主机名:{hostname}\n端口:{port}\n协议:{scheme}')
输出:
主机名:www.baidu.com
端口:80
协议:http
url解析库 urlparse 详细参考
《python3 url解析 urllib.parse.urlparse 库简介》
https://blog.csdn.net/whatday/article/details/107746381