これを元にしました https://misskey.04.si/notes/9ipkkt4ygz
Last active
September 5, 2023 15:20
-
-
Save WinLinux1028/1e3e3cd8bdfabfb05e40d9b6f685c560 to your computer and use it in GitHub Desktop.
ドメインが書かれたテキストファイルから同じTLDの数を数えるやつ
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 | |
from publicsuffix2 import fetch, get_tld | |
from pprint import pprint | |
psl_file = fetch() | |
length = 9000 | |
headers = { | |
"Content-Type": "application/json", | |
} | |
hosts = {} | |
cnt = 0 | |
with open(sys.argv[1]) as f: | |
for domain in f: | |
domain = str.strip(domain) | |
cnt += 1 | |
tld = get_tld(domain, psl_file=psl_file) | |
print(f"domain:{domain} tld:{tld}") | |
if tld in hosts: | |
hosts[tld] += 1 | |
else: | |
hosts[tld] = 1 | |
hosts = sorted(hosts.items(), key=lambda x: x[1], reverse=True) | |
with open("result.csv", "w") as f: | |
for tld, count in hosts: | |
f.write(f"{tld},{count}\n") | |
pprint(hosts) | |
print(f"total server:{cnt}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment