python基础

随机字符串检查域名是否被注册

#!/usr/bin/env python
#coding=utf-8

from time import sleep
from aliyunsdkcore.client import AcsClient
from aliyunsdkcore.acs_exception.exceptions import ClientException
from aliyunsdkcore.acs_exception.exceptions import ServerException
from aliyunsdkdomain.request.v20180129.CheckDomainRequest import CheckDomainRequest
import json
import random

class DomainAvailableCheck:
    def __init__(self):
        # self.dot_list = ['.com', '.cn', '.net', '.com.cn', '.org']
        self.dot_list = ['.com', '.cn']
        self.client = AcsClient('ak', 'sk', 'cn-hangzhou')

    def domain_list(self, word_str):
        domains = []
        for dot in self.dot_list:
            domains.append(word_str+dot)
        return domains

    def check_domain(self, domain):
        request = CheckDomainRequest()
        request.set_accept_format('json')
        request.set_DomainName(domain)
        response = self.client .do_action_with_exception(request)
        # print(str(response, encoding='utf-8'))
        res = json.loads(str(response, encoding='utf-8'))
        # print(res)
        return res

if __name__ == '__main__':
    check = DomainAvailableCheck()
    str_word = 'abcdefghijklmnopqrstuvwxyz'
    k_list = []
    while True:
        a = random.choice(str_word)
        b = random.choice(str_word)
        c = random.choice(str_word)
        d = c
        domain_word = a + b + c + d
        if domain_word not in k_list:
            for domain in check.domain_list(domain_word):
                resp = check.check_domain(domain)
                if resp["Avail"] == 1:
                    # print(domain)
                    print(domain + ' 可以注册!')
                sleep(0.2)
            k_list.append(domain_word)
        # else:
        #     print(domain_word + ' 已经在列表中!')

留言

您的电子邮箱地址不会被公开。 必填项已用*标注

闽ICP备20008591号-1