Last active
September 17, 2022 11:27
-
-
Save qurbat/911abf4f39ee76806af01022cde0d4c7 to your computer and use it in GitHub Desktop.
Extract root domain names from text file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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