Last active
January 10, 2023 10:23
-
-
Save dadevel/89ec05cd52676e249e1ad13eff951785 to your computer and use it in GitHub Desktop.
Second Level Domain Extractor
This file contains hidden or 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/env python3 | |
| import sys | |
| import urllib.parse | |
| import tldextract | |
| # pip3 install --user tldextract | |
| def main() -> None: | |
| for line in sys.stdin: | |
| url = urllib.parse.urlparse(line) | |
| fqdn = url.netloc if url.scheme and url.netloc else line | |
| result = tldextract.extract(fqdn) | |
| print(f'{result.domain}.{result.suffix}') | |
| if __name__ == '__main__': | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment