#!/usr/bin/env python # -*- coding: utf-8 -*- """ 测试关注标签坐标功能 用于验证关注标签坐标 (712, 169) 是否正确配置 """ import re import os def test_coordinates(): """测试关注标签坐标是否正确配置""" script_dir = os.path.dirname(os.path.abspath(__file__)) douyin_fudai_path = os.path.join(script_dir, "douyin_fudai.py") if not os.path.exists(douyin_fudai_path): print("错误: 未找到 douyin_fudai.py 文件") return False with open(douyin_fudai_path, "r", encoding="utf-8") as f: content = f.read() # 检查坐标定义 x_match = re.search(r'self\.yanghao_follow_tab_x\s*=\s*(\d+)', content) y_match = re.search(r'self\.yanghao_follow_tab_y\s*=\s*(\d+)', content) if not x_match or not y_match: print("错误: 未找到关注标签坐标定义") return False x_coord = int(x_match.group(1)) y_coord = int(y_match.group(1)) print("=" * 50) print("关注标签坐标测试") print("=" * 50) print(f"当前配置的坐标: ({x_coord}, {y_coord})") print(f"预期坐标: (712, 169)") if x_coord == 712 and y_coord == 169: print("\n[OK] 坐标配置正确!") # 检查坐标使用位置 usage_pattern = r'follow_tab_x\s*=\s*int\(getattr\(self,\s*"yanghao_follow_tab_x"' if re.search(usage_pattern, content): print("[OK] 坐标在使用位置正确获取") else: print("[WARN] 警告: 未找到坐标使用代码") # 检查日志输出 log_pattern = r'检测到推荐页面,点击关注标签 ->' if re.search(log_pattern, content): print("[OK] 日志输出代码存在") print("\n测试通过!") print("\n下一步:") print("1. 运行脚本,观察日志中是否显示: 检测到推荐页面,点击关注标签 -> (712, 169)") print("2. 验证点击位置是否准确落在关注标签上") print("3. 如果点击位置不准确,可以微调坐标值") return True else: print(f"\n[ERROR] 坐标配置不匹配!") print(f" 当前: ({x_coord}, {y_coord})") print(f" 预期: (712, 169)") return False if __name__ == "__main__": success = test_coordinates() exit(0 if success else 1)