过期域名是指在域名注册期限到期后,域名所有者未能及时续费,导致域名被注册商收回并重新开放给公众注册的状态。过期域名未被删除通常指的是域名在过期后,其DNS记录、网站内容等仍然保留在服务器上,没有被完全清理。
import requests
import json
# 腾讯云API密钥和密钥ID
secret_id = 'your_secret_id'
secret_key = 'your_secret_key'
# 腾讯云域名查询API
url = 'https://cns.tencentcloudapi.com/?Action=DomainList&Version=2018-03-12'
headers = {
'Authorization': f'TC3-HMAC-SHA256 Credential={secret_id}/2018-03-12/cns/tc3_request, SignedHeaders=content-type;host;x-tc-action;x-tc-timestamp, Signature=...',
'Content-Type': 'application/json',
'Host': 'cns.tencentcloudapi.com'
}
response = requests.get(url, headers=headers)
domains = json.loads(response.text)['DomainList']
# 检查过期域名并删除
for domain in domains:
if domain['Status'] == 'expired':
delete_url = f'https://cns.tencentcloudapi.com/?Action=DeleteDomain&Version=2018-03-12&DomainName={domain["DomainName"]}'
delete_response = requests.delete(delete_url, headers=headers)
if delete_response.status_code == 200:
print(f'Domain {domain["DomainName"]} deleted successfully.')
else:
print(f'Failed to delete domain {domain["DomainName"]}.')
领取专属 10元无门槛券
手把手带您无忧上云