update control

This commit is contained in:
yeongpin
2025-01-14 18:58:35 +08:00
parent f358ee9aec
commit 3edef109d4
2 changed files with 50 additions and 30 deletions

View File

@@ -215,8 +215,17 @@ class BrowserControl:
def get_verification_code(self):
"""从邮件中获取验证码"""
try:
# 查找包含验证码的div使用更精确的XPath
code_div = self.browser.ele('xpath://div[contains(@style, "font-family:-apple-system") and contains(@style, "font-size: 28px") and contains(@style, "letter-spacing: 2px") and contains(@style, "color: rgba(32, 32, 32, 1)")]')
# 使用新的 XPath 定位验证码
code_div = self.browser.ele('xpath://div[contains(@style, "font-family:-apple-system") and contains(@style, "font-size:28px") and contains(@style, "letter-spacing:2px") and contains(@style, "color:#202020")]')
# 如果找不到,尝试备用选择器
if not code_div:
code_div = self.browser.ele('xpath://div[contains(@style, "font-size:28px") and contains(@style, "letter-spacing:2px") and contains(@style, "line-height:30px")]')
# 如果还找不到,尝试更宽松的选择器
if not code_div:
code_div = self.browser.ele('xpath://div[contains(@style, "font-size:28px") and contains(@style, "letter-spacing:2px")]')
if code_div:
verification_code = code_div.text.strip()
if verification_code.isdigit() and len(verification_code) == 6:
@@ -226,17 +235,11 @@ class BrowserControl:
print(f"{Fore.RED}Verification Code Format Error | 验证码格式不正确: {verification_code}{Style.RESET_ALL}")
return None
else:
# 尝试备用XPath
code_div = self.browser.ele('xpath://div[contains(@style, "font-size: 28px") and contains(@style, "letter-spacing: 2px") and contains(@style, "color: rgba(32, 32, 32, 1)")]')
if code_div:
verification_code = code_div.text.strip()
if verification_code.isdigit() and len(verification_code) == 6:
print(f"{Fore.GREEN}Found Verification Code | 找到验证码: {verification_code}{Style.RESET_ALL}")
return verification_code
print(f"{Fore.RED}No Verification Code Found | 未找到验证码{Style.RESET_ALL}")
print(f"{Fore.YELLOW}No Verification Code Found | 未找到验证码{Style.RESET_ALL}")
return None
except Exception as e:
print(f"{Fore.RED}Get Verification Code Failed | 获取验证码时发生错误: {str(e)}{Style.RESET_ALL}")
print(f"{Fore.RED}Get Verification Code Error | 获取验证码时发生错误: {str(e)}{Style.RESET_ALL}")
return None
def fill_verification_code(self, code):