介绍
本教程提供2025年6月最新版的Python代码,用于检测指定域名在抖音平台内是否被封禁。通过调用抖音官方API接口,可以快速获取域名状态信息,返回结果中status为1表示域名正常,为0表示域名被封禁。
Python代码
import requests
from urllib.parse import quote
import time
def check_douyin_domain_status_2025(target_url):
"""
2025年6月最新版抖音域名封禁状态检测
:param target_url: 要检测的完整URL(如:https://baidu.com)
:return: 包含状态码和消息的字典
"""
api_base = "https://api.wxapi.work/dy/api.php"
# 参数验证
if not target_url:
return {
"status": "0",
"message": "URL不能为空"
}
if not target_url.startswith(('http://', 'https://')):
return {
"status": "0",
"message": "URL必须以http://或https://开头"
}
try:
# 编码URL参数
encoded_url = quote(target_url, safe='')
# 构造完整请求URL(2025年6月最新API地址)
api_url = f"{api_base}?url={encoded_url}"
# 添加请求头模拟浏览器访问
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36',
'Accept': 'application/json'
}
# 发送GET请求(添加3秒超时)
response = requests.get(api_url, headers=headers, timeout=3)
response.raise_for_status()
# 解析JSON响应
result = response.json()
# 标准化返回结果
if "status" in result:
return {
"status": "1" if result["status"] == "1" else "0",
"message": result.get("message", "域名状态未知")
}
else:
return {
"status": "0",
"message": "无效的API响应格式"
}
except requests.exceptions.Timeout:
return {
"status": "0",
"message": "请求超时,请检查网络连接"
}
except requests.exceptions.RequestException as e:
return {
"status": "0",
"message": f"API请求失败: {str(e)}"
}
# 示例用法
if __name__ == "__main__":
# 要检测的URL列表(2025年6月最新测试案例)
test_urls = [
"https://douyin.com", # 抖音官方域名
"https://baidu.com", # 常用域名
"https://example.com", # 测试域名
"invalidurl", # 无效URL测试
"" # 空URL测试
]
print("抖音域名状态检测报告(2025年6月)")
print("="*50)
print("状态码说明: 1=正常, 0=被封禁或异常\n")
for url in test_urls:
print(f"\n检测目标: {url if url else '[空URL]'}")
result = check_douyin_domain_status_2025(url)
print(f"检测状态: {'正常' if result['status'] == '1' else '异常'}")
print(f"详细结果: {result['message']}")
print(f"完整响应: {result}")
print("-"*50)
time.sleep(1) # 避免请求过于频繁
使用方法
-
安装依赖库:
pip install requests
-
修改代码中的
test_urls
列表,添加你要检测的完整URL(必须包含http://或https://) -
运行脚本,将得到类似以下结果:
{ "status": "1", "message": "域名正常" }
或
{ "status": "0", "message": "域名被封禁" }
2025年6月更新说明
- 更新了API端点地址为最新版本
- 增加了更严格的URL格式验证
- 添加了现代浏览器User-Agent头
- 优化了错误处理机制
- 增加了请求超时设置
- 添加了防频繁请求的延迟
返回结果说明
status
:- "1" 表示域名正常
- "0" 表示域名被封禁或检测异常
message
: 详细的状态信息或错误原因
注意事项
- 必须提供完整的URL(包含http://或https://)
- 抖音API可能有访问频率限制,建议间隔1秒以上
- 2025年API地址如有变更,请及时更新代码
- 本工具仅供合法用途,禁止用于恶意检测
常见问题解决方案
- 返回"URL不能为空" → 检查是否提供了有效的URL参数
- 返回"请求超时" → 检查网络连接或增加timeout值
- 返回"API请求失败" → 确认API服务是否可用
- 异常状态 → 建议多次检测确认结果一致性