python - How to through a list with urlparse -


how through list urlparse, example:

from urlparse import urlparse class paste(models.model):     paste = models.textfield()      def render_url(self):         return ['{0}'.format(url) url in self.paste.split()]      def server(self):         url_parse = urlparse(self.render_url)         return url_parse.hostname.lstrip('www.')  example:                 paste:                        result http://www.example2.com/32/skwieq.html >> hostname example2.com http://www.example2.com/2/cxvxcveq.html >> hostname example2.com http://www.example4.com/10/skasd1ieq.html >> hostname example4.com http://www.example4.com/x/ooqweeq.html >> hostname example4.com 

any suggestions thanks.

this how urlparse works:

>>> urlparse import urlparse >>> o = urlparse('http://www.example2.com/32/skwieq.html') >>> o    parseresult(scheme='http', netloc='www.example2.com', path='/32/skwieq.html',             params='', query='', fragment='') 

to result in desired format:

>>> o.hostname.split('.', 1)[1]  example2.com   def server(self):     urlparse import urlparse     url_parse = urlparse(self.render_url)     hostname = none     hostname = url_parse.hostname.split('.', 1)[1] if url_parse.hostname     return hostname 

Comments

Popular posts from this blog

ios - iPhone/iPad different view orientations in different views , and apple approval process -

java Extracting Zip file -

C# WinForm - loading screen -