Skip to content

Instantly share code, notes, and snippets.

@random-robbie
Created April 14, 2023 12:04
Show Gist options
  • Save random-robbie/ce0f9d722929a20730f197fe6422334b to your computer and use it in GitHub Desktop.
Save random-robbie/ce0f9d722929a20730f197fe6422334b to your computer and use it in GitHub Desktop.
Accepts file or stdin and grabs all TLD domains.
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