McLeodx McLeodx - 11 months ago 51
Python Question

Extract domain name only from url, getting rid of the path (Python)

I've been trying to extract the domain names from a list of urls, so that
would become
. I'm trying to find a clean way of doing it that will be adaptable to various gtlds and cctlds.


You can do it using regex like this:

import re

text = ''

m ='(https?:\/\/[^:\/\n]+)', text)
if m:

Working example