Ad

Write a function that when given a URL as a string, parses out just the domain name and returns it as a string. For example:

domain_name("http://github.com/carbonfive/raygun") == "github"
domain_name("http://www.zombie-bites.com") == "zombie-bites"
domain_name("https://www.cnet.com") == "cnet"

def domain_name(url):
    begin = 0
    if "https://" in url:
        begin += 8 
    elif "http://" in url:
        begin += 7
    if "www" in url:
        begin += 4
    return url[begin:].split(".")[0]