且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用 Python 从 URL 获取子域

更新时间:2023-02-23 21:31:53

urlparse.urlparse 将 URL 拆分为协议、位置、端口等,然后可以通过 拆分位置. 获取子域.

urlparse.urlparse will split the URL into protocol, location, port, etc. You can then split the location by . to get the subdomain.

url = urlparse.urlparse(address)
subdomain = url.hostname.split('.')[0]