python 获取https或http的网址如http511784424040获取到51178442
你可以使用Python的urllib库来获取网址中的主机名。具体的方法是使用urlparse函数解析URL,并从结果中提取主机名。下面是一个示例代码:
from urllib.parse import urlparse
url = "http://51.178.44.2:4040"
parsed_url = urlparse(url)
hostname = parsed_url.hostname
print(hostname)
运行以上代码,你会得到输出结果为:51.178.44.2。
原文地址: https://www.cveoy.top/t/topic/hLXN 著作权归作者所有。请勿转载和采集!