根据URL地址获取域名
#coding:utf-8 import urllib #根据URL获取域名 def getdomain(url): proto, rest = urllib.splittype(url) host, rest = urllib.splithost(rest) return host print getdomain("http://www.cnblogs.com/goodhacker/admin/EditPosts.aspx?opt=1")
输出结果为:www.cnblogs.com