Skip to content

Instantly share code, notes, and snippets.

@qurbat
Last active September 17, 2022 11:27
Show Gist options
  • Save qurbat/911abf4f39ee76806af01022cde0d4c7 to your computer and use it in GitHub Desktop.
Save qurbat/911abf4f39ee76806af01022cde0d4c7 to your computer and use it in GitHub Desktop.
Extract root domain names from text file
#!/usr/bin/python
import io
import tldextract
infile = "domains.txt"
def extract(infile):
with io.open(infile) as f:
for line in f:
domain = line.strip('\n')
extracted = tldextract.extract(domain)
if extracted.registered_domain:
print("{}".format(extracted.registered_domain))
if __name__ == '__main__':
extract(infile)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment