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"?
-
docs.python.org/library/urlparse.htmlvartec– vartec2009-02-03 18:02:11 +00:00Commented Feb 3, 2009 at 18:02
-
Just to clarify, do you really want just "faqs.org" or do you want "www.faqs.org"? Trying to get the former is a Bad Idea, as it isn't portable to domains like "www.amazon.co.uk".Ben Blank– Ben Blank2009-02-03 18:12:11 +00:00Commented Feb 3, 2009 at 18:12
Add a comment
|
3 Answers
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
1 Comment
SilentGhost
netloc might includes port number