Python3 URL 解析:提取协议和域名
import re
while True: url = input('请输入一个 url:') match = re.match(r'(https?://)?([a-zA-Z0-9-]+.)+[a-zA-Z]{2,3}', url) if match: protocol = match.group(1)[:-3] if match.group(1) else 'http' domain = match.group(2)[:-1] print('协议:', protocol) print('域名:', domain) break else: print('输入错误,请重新输入')
原文地址: https://www.cveoy.top/t/topic/nMe8 著作权归作者所有。请勿转载和采集!