from urlparse import urlparse url_str = "http://www.163.com/mail/index.htm" url = urlparse(url_str) print 'protocol:',url.scheme print 'hostname:',url.hostname print 'port:',url.port print 'path:',url.path i = len(url.path) - 1 while i > 0: if url.path[i] == '/': break i = i - 1 print 'filename:',url.path[i+1:len(url.path)]