Python: get domain name from url 

Joined:
04/09/2007
Posts:
565

December 24, 2009 22:25:38    Last update: December 24, 2009 22:26:11
Use the [url=http://docs.python.org/library/urlparse.html]urlparse[/url] module to parse a URL into parts.

The urlparse function parses a URL into six components, returning a 6-tuple. This corresponds to the general structure of a URL: scheme://netloc/path;parameters?query#fragment

>>> from urlparse import urlparse
>>> parts = urlparse('http://www.google.com/search?hl=en&source=hp&q=python')
>>> parts
('http', 'www.google.com', '/search', '', 'hl=en&source=hp&q=python', '')
>>>
[ Comment  | Tags ]
 
Easy email testing with http://www.ximailstop.com