From 7892a17bfa0ecab50d260cafb3c28a4223180a14 Mon Sep 17 00:00:00 2001 From: yzqzss Date: Mon, 7 Feb 2022 16:00:44 +0800 Subject: [PATCH] =?UTF-8?q?=E7=B2=BE=E7=AE=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/main.py b/main.py index 450134e..c5fb1cd 100644 --- a/main.py +++ b/main.py @@ -7,25 +7,25 @@ try: githubip = urllib.request.urlopen('https://api.github.com/meta') githubip = str(githubip.read()) lines = urllib.request.urlopen('https://github.com/timqian/chinese-independent-blogs/raw/master/blogs-original.csv') - lines = str(lines.read()) - lines = lines.splitlines() + lines = lines.read().decode().splitlines() + print(lines) except: - print('无法访问GitHub,请检查网络。') -else: - with open('gh-domains.txt', 'w') as f: + print('无法访问 Github,请检查网络。') + +with open('gh-domains.txt', 'w') as f: for line in lines[1:]: - print(num) - num = num + 1 - line = line.replace(" ", "").split(',') - res = urllib.parse.urlparse(line[1]) - domain = res.netloc - try: - ip = socket.gethostbyname(domain) - ip = ip.split('.') - ip_head = ip[0]+'.'+ip[1]+'.'+ip[2] - isfind = githubip.find(ip_head) - if isfind != -1 : - f.write(domain+"\n") - print(domain+" 是GH-Pages!") - except: - continue + print(num) + num = num + 1 + line = line.replace(" ", "").split(',') + res = urllib.parse.urlparse(line[1]) + domain = res.netloc + try: + ip = socket.gethostbyname(domain) + ip = ip.split('.') + ip_head = ip[0]+'.'+ip[1]+'.'+ip[2] + isfind = githubip.find(ip_head) + if isfind != -1 : + f.write(domain+"\n") + print(domain+" 是GH-Pages!") + except: + continue