There are a lot of great tools out there to extract urls/domais/ips/etc from text, but one of the most useful that I've found was tldextract.

You can easily install it with pip (pip install tldextract), the project page has some documentation and some examples.

A small code snippet that opens a text file and extracts the domain part ( www.website.co.uk is transormed into website.co.uk for example )

import tldextract
with open("input.txt") as f:
    for line in f:
        extracted = tldextract.extract(line)
        print "{}.{}".format(extracted.domain, extracted.suffix)