根据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
posted @ 2013-07-02 11:42  bamb00  阅读(1808)  评论(0编辑  收藏  举报