Answers for "python urlparse get domain"

0

python urlparse get domain

from urllib.parse import urlparse

domain = urlparse('http://www.example.test/foo/bar').netloc
print(domain) # --> www.example.test

#To get without the subdomain
t = urlparse('http://abc.hostname.com/somethings/anything/').netloc
print ('.'.join(t.split('.')[1:])) # --> hostname.com
Posted by: Guest on March-29-2021

Python Answers by Framework

Browse Popular Code Answers by Language