McLeodx McLeodx - 1 year ago 114
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.

Answer Source

You can do it using regex like this:

import re

text = ''

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

Working example

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download