Python: get domain name from url 

Joined:
04/09/2007
Posts:
710

December 24, 2009 22:25:38    Last update: April 04, 2011 13:48:24
Use the urlparse 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', '')
>>>
Share |
| Comment  | Tags
 
Easy email testing with http://www.ximailstop.com