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):

View File

@ -247,7 +247,7 @@ class CursorRegistration:
print(f"{Fore.YELLOW}{EMOJI['VERIFY']} Handle Turnstile | 处理 Turnstile 验证...{Style.RESET_ALL}")
# 设置最大等待时间(秒)
max_wait_time = 5
max_wait_time = 10 # 增加等待时间
start_time = time.time()
while True:
@ -255,32 +255,49 @@ class CursorRegistration:
# 检查是否超时
if time.time() - start_time > max_wait_time:
print(f"{Fore.YELLOW}{EMOJI['WAIT']} Not Detect Turnstile | 未检测到 Turnstile 验证,继续下一步...{Style.RESET_ALL}")
time.sleep(2) # 添加短暂延迟
break
# 检查是否存在验证框
challengeCheck = (
self.signup_tab.ele("@id=cf-turnstile", timeout=1)
.child()
.shadow_root.ele("tag:iframe")
.ele("tag:body")
.sr("tag:input")
)
try:
challengeCheck = (
self.signup_tab.ele("@id=cf-turnstile", timeout=1)
.child()
.shadow_root.ele("tag:iframe")
.ele("tag:body")
.sr("tag:input")
)
if challengeCheck:
challengeCheck.click()
time.sleep(2)
print(f"{Fore.GREEN}{EMOJI['SUCCESS']} Turnstile Passed | 验证通过{Style.RESET_ALL}")
break
if challengeCheck:
challengeCheck.click()
time.sleep(3) # 增加点击后的等待时间
print(f"{Fore.GREEN}{EMOJI['SUCCESS']} Turnstile Passed | 验证通过{Style.RESET_ALL}")
time.sleep(2) # 确保验证完全完成
break
except:
pass
# 检查是否已经通过验证(检查下一步的元素是否存在)
if self.signup_tab.ele("@name=password"):
print(f"{Fore.GREEN}{EMOJI['SUCCESS']} Verification Passed | 验证已通过{Style.RESET_ALL}")
break
try:
if (self.signup_tab.ele("@name=password", timeout=0.5) or
self.signup_tab.ele("@name=email", timeout=0.5) or
self.signup_tab.ele("@data-index=0", timeout=0.5)):
print(f"{Fore.GREEN}{EMOJI['SUCCESS']} Verification Passed | 验证已通过{Style.RESET_ALL}")
time.sleep(2) # 添加短暂延迟
break
except:
pass
except:
# 等待短暂时间后继续检查
time.sleep(0.5)
continue
time.sleep(1)
except Exception as e:
print(f"{Fore.RED}{EMOJI['ERROR']} Turnstile Error | Turnstile 处理出错: {str(e)}{Style.RESET_ALL}")
time.sleep(2) # 出错时等待更长时间
break
# 最后再等待一下,确保页面加载完成
time.sleep(2)
def _get_account_info(self):
"""获取账户信息和 Token"""