Created
April 14, 2023 12:04
-
-
Save random-robbie/ce0f9d722929a20730f197fe6422334b to your computer and use it in GitHub Desktop.
Accepts file or stdin and grabs all TLD domains.
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
import sys | |
import tldextract | |
def extract_main_domain(url): | |
return tldextract.extract(url).registered_domain | |
if __name__ == '__main__': | |
if len(sys.argv) > 1: | |
# read from file | |
with open(sys.argv[1], 'r') as f: | |
for line in f: | |
domain = extract_main_domain(line.strip()) | |
print(domain) | |
else: | |
# read from stdin | |
for line in sys.stdin: | |
domain = extract_main_domain(line.strip()) | |
print(domain) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment