I am new to Python and it seems to have a lot of nice functions that I don't know about. What function can I use to get the root site name? For example, how would I get faqs.org if I gave the function the URL "http://www.faqs.org/docs/diveintopython/kgp_commandline.html"?
+5
A:
>>> from urllib.parse import urlparse
>>> urlparse('http://www.cwi.nl:80/%7Eguido/Python.html').hostname
'www.cwi.nl'
SilentGhost
2009-02-03 17:57:18
+1
A:
The much overlooked urlparse module:
from urlparse import urlparse
scheme, netloc, path, params, query, fragment = urlparse("http://www.faqs.org/docs/diveintopython/kgp_commandline.html")
print netloc
Alabaster Codify
2009-02-03 17:58:24
netloc might includes port number
SilentGhost
2009-02-03 18:00:05
+1
A:
What version of Python are you learning with? Note that SilentGhost's answer is for Python 3.0, while Alabaster Codify's will work with the 2.x series.
Barry Fandango
2009-02-03 18:08:01