用pythonhois测试域名可用性

2024-05-16 19:30:09 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在成功使用pythonwhois(与pip install ...一起安装)来检查.com域的可用性:

import pythonwhois
for domain in ['aaa.com', 'bbb.com', ...]:
    details = pythonwhois.get_whois(domain)
    if 'No match for' in str(details):   # simple but it works!
        print domain 

但是:

  • 有点慢(平均每秒2个请求)
  • {26}如果CD26请求不被CD26}列出?
    (我正在测试???mail.com的可用性,其中?是{})

问题:有没有比为每个域执行一个whois请求更好的方法来检查可用性?


编辑:这项工作在9572秒内完成,截至2017年11月,如果有人有兴趣启动电子邮件服务,那么???mail.com形式的所有可用域的here is the full list!在


Tags: installpipinimportcomfordomainmail
1条回答
网友
1楼 · 发布于 2024-05-16 19:30:09

你应该把你正在做的事情平行化。由于函数花费的大部分时间都在等待中,因此可以一次验证大量工作(不限于处理器数量)。示例:

import pythonwhois
from joblib import Parallel, delayed, cpu_count
n_jobs = 100 # works in parallel
def f(domain):
    details = pythonwhois.get_whois(domain)
    if 'No match for' in str(details):   # simple but it works!
        print(domain)
        return domain
    else:
        return None

domains= ['aaa.com', 'bbb.com', 'ccc.com', 'bbbaohecraoea.com']
result = Parallel(n_jobs=n_jobs, verbose=10)(delayed(f)(domain) for domain in domains)

# create a list with the available domains
available_domains=[domains[idx] for idx,r in enumerate(result) if r!=None]
print(available_domains)
# Result
# ['bbbaohecraoea.com']

相关问题 更多 >