python URL提取域名

不啰嗦

def Match_URL(url):
    scheme_chars = ('abcdefghijklmnopqrstuvwxyz'
                    'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
                    '0123456789'
                    '+-.')
    SCHEME_RE = re.compile(r'^([' + scheme_chars + ']+:)?//')
    netloc = SCHEME_RE.sub("", url) \
        .partition("/")[0] \
        .partition("?")[0] \
        .partition("#")[0] \
        .split("@")[-1] \
        .partition(":")[0] \
        .strip() \
        .rstrip(".")
    return netloc


网友评论(0)