title: Extract domain name from URL in Python
body: <p>I am tring to extract the domain names out of a list of URLs. Just like in
  <a href="https://stackoverflow.com/questions/18331948/extract-domain-name-from-the-url">https://stackoverflow.com/questions/18331948/extract-domain-name-from-the-url</a><br>
  My problem is that the URLs can be about everything, few examples:<br>
  <code>m.google.com</code> =&gt; <code>google</code><br>
  <code>m.docs.google.com</code> =&gt; <code>google</code><br>
  <code>www.someisotericdomain.innersite.mall.co.uk</code> =&gt; <code>mall</code><br>
  <code>www.ouruniversity.department.mit.ac.us</code> =&gt; <code>mit</code><br>
  <code>www.somestrangeurl.shops.relevantdomain.net</code> =&gt; <code>relevantdomain</code> <br>
  <code>www.example.info</code> =&gt; <code>example</code><br>
  And so on..<br>
  The diversity of the domains doesn't allow me to use a regex as shown in <a href="https://stackoverflow.com/questions/569137/how-to-get-domain-name-from-url">how to get domain name from URL</a> (because my script will be running on enormous amount of urls from real network traffic, the regex will have to be enormous in order to catch all kinds of domains as mentioned).<br>
  Unfortunately my web research the didn't provide any efficient solution.<br>
  Does anyone have an idea of how to do this ?<br>
  Any help will be appreciated ! <br>
  Thank you</p>