我想使用此Python代码获得合法域名的过滤器。 我看不出代码有什么问题,也查阅了很多网站。它无法区分正确和错误的域名。
def getDomains():
with open('domains.txt', 'r+') as f:
for domainName in f.read().splitlines():
domains.append(domainName)
def run():
for dom in domains:
if dom is not None and dom != '':
details = pythonwhois.get_whois(dom)
if str(details) is None:
unavailable.append(dom)
else:
available.append(dom)
结果应该是这样的:
可用域
google.com youtube.com
<小时/>不可用的域
xcdv345.hgt.com Letstrythis12398.net
最佳答案
即使域名未注册,pythonwhois.get_whois
也不是 None
。
尝试打印 pythonwhois.get_whois('jjj876686.njerfjr')
的结果,例如字段 contacts
始终存在(结果和 str(result) ,与 None
不同)(请参阅 http://cryto.net/pythonwhois/usage.html#pythonwhois_get_whoisdomainnormalized )
关于python - 域名检测,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55909300/