python - 域名检测

标签 python list

我想使用此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/

相关文章:

python - 名称错误 : name of the class not defined inside the class itself - python

python - pandas 数据格式保存 DateTimeIndex

list - Prolog:不带累加器的最大值谓词

python - 计算 2 个字符串之间的差异(Levenshtein 距离)

python - pytorch中引入nn.Parameter的目的

python - 尝试在没有 forms.py 的情况下使用文件上传 - 'InMemoryUploadedFile' 对象不可调用

python - 尝试将数据从 C++ 发送到 Python 并使用套接字 C++、C++ sendto() 和 python recvfrom() 工作但不是反向

python - 从 Python : passing list of numpy pointers 调用 C

python - 来自两个列表的随机元素 - Python

python - 如何对坐标列表进行排序?