背景介绍
阿里云界面查询相关域名需要登录阿里云控制台进行管理查询相关域名信息. (1).登录阿里云需要阿里云账号 和相关登录权限 (2).控制台可能存在误操作风险;
针对域名可管理性故开发抓取域名脚本抓取域名操作流程;
(1).阿里云控制台申请ak,sk (程序操作权限和授权密码)
(2).安装阿里云核心sdk包以及云解析包;
(3).postman发送请求携带请求参数;
(4).返回云端参数;
3.安装阿里云域名抓取sdk支持包
pip ×××tall aliyun-python-sdk-core-v3==2.13.3pip ×××all aliyun-python-sdk-alidns==2.0.7
4.实例代码;
####阿里云域名路由######@domainUrl.route('/aliyun/api', methods=['GET', 'POST', 'DELETE'])def aadalimainMain(): if request.method == "GET": msg = "不支持此方法" return Response(json.dumps({"code": 1, "data": msg + request.method}), mimetype='application/json') elif request.method == "POST": Data = request.get_json() domainName = Data.get('domain_name') getdomain = alidomainManager() data = getdomain.qeuryDomain(domainName) return Response(json.dumps({"code": 0, "len": len(data), "data": data}), mimetype='application/json') elif request.method == "delete": pass else: msg = "不支持此方法" return Response(json.dumps({"code": 1, "data": msg + request.method}), mimetype='application/json')class alidomainManager(object): def __init__(self): self.client = AcsClient("程序的ak","程序sk", "区域") def qeuryDomain(self, domain): domainlist = self.getaliDomainGroup() if domain in domainlist: return self.getaliDomain(domain) else: return "没有此域名信息" #######获取分页页码和每页数据进行递归查询域名数量######### def getaliPageSize(self, fun, parameter1, parameter2, domain=None, pageNumber=1, pageSize=100, D=[]): try: request = fun request.set_accept_format('json') request.set_PageSize(pageSize) if domain: request.set_DomainName(domain) request.set_PageNumber(pageNumber) response = json.loads(self.client.do_action_with_exception(request)) if response is not None and len(response.get(parameter1).get(parameter2)) > 0: Record_list = response.get(parameter1).get(parameter2) if Record_list and len(Record_list) > 0: for Record in Record_list: D.append(Record) self.getaliPageSize(fun, parameter1, parameter2, domain, pageNumber + 1, pageSize, D) return D except Exception as e: msg = "系统内部,参数不足" return e + msg ##########获取域名############ def getaliDomain(self, domain): DomainRecordsKey = "DomainRecords" RecordKey = "Record" return self.getaliPageSize(DescribeDomainRecordsRequest(), DomainRecordsKey, RecordKey, domain, pageNumber=1, pageSize=100, D=[]) ###########获取全部域名列表########### def getaliDomainGroup(self): Doma×××Key = "Doma×××" Domain = "Domain" D = [] for i in self.getaliPageSize(DescribeDoma×××Request(), Doma×××Key, Domain, None, pageNumber=1, pageSize=100, D=[]): D.append(i.get("DomainName")) return D
5.执行域名结果输出;