0

I would like to write a function when it's given a URL as a string, parses out just the domain name and returns it as a string.

url = "http://google.com/youtube/win" > domain name = "google"
url = "http://www.foodpub.com/home" > domain name = "foodpub"
url = "http://www.foodpub.com/home" > domain name = "foodpub"
url = "https://www.games.com" > domain name = "games"`

I have figure that you would need to import 'from urllib.parse import urlparse'

Barmar
  • 741,623
  • 53
  • 500
  • 612
  • What about `www.google.co.uk`? The general rules are different for every top-level domain. – Barmar May 05 '23 at 19:52
  • The domain name of "google.com" is not "google", it is "google.com". You can use the `hostname` property of what urllib provides but separating out just part of the domain name is dangerous. You probably don't want to confuse "google.xxx" with "google.com". – David Conrad May 05 '23 at 19:57

0 Answers0