python提取url中的域名和端口号

python提取url中的域名和端口号

import urllib 
proto, rest = urllib.splittype("http://www.open-open.com/") 
host, rest = urllib.splithost(rest) 
print host 
host, port = urllib.splitport(host) 
if port is None: 
   port = 80 
print port 

编程技巧