forked from chengazhen/cursor-auto-free
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_email_code.py
80 lines (64 loc) · 2.37 KB
/
get_email_code.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
from DrissionPage.common import Keys
import time
import re
class EmailVerificationHandler:
def __init__(self, browser, mail_url="https://tempmail.plus"):
self.browser = browser
self.mail_url = mail_url
def get_verification_code(self, email):
username = email.split("@")[0]
code = None
try:
print("正在处理...")
# 打开新标签页访问临时邮箱
tab_mail = self.browser.new_tab(self.mail_url)
self.browser.activate_tab(tab_mail)
# 输入用户名
self._input_username(tab_mail, username)
# 等待并获取最新邮件
code = self._get_latest_mail_code(tab_mail)
# 清理邮件
self._cleanup_mail(tab_mail)
# 关闭标签页
tab_mail.close()
except Exception as e:
print(f"获取验证码失败: {str(e)}")
return code
def _input_username(self, tab, username):
while True:
if tab.ele("@id=pre_button"):
tab.actions.click("@id=pre_button")
time.sleep(0.5)
tab.run_js('document.getElementById("pre_button").value = ""')
time.sleep(0.5)
tab.actions.input(username).key_down(Keys.ENTER).key_up(Keys.ENTER)
break
time.sleep(1)
def _get_latest_mail_code(self, tab):
code = None
while True:
new_mail = tab.ele("@class=mail")
if new_mail:
if new_mail.text:
tab.actions.click("@class=mail")
break
else:
break
time.sleep(1)
if tab.ele("@class=overflow-auto mb-20"):
email_content = tab.ele("@class=overflow-auto mb-20").text
verification_code = re.search(
r"verification code is (\d{6})", email_content
)
if verification_code:
code = verification_code.group(1)
print("马上就要成功了")
else:
print("执行失败")
return code
def _cleanup_mail(self, tab):
if tab.ele("@id=delete_mail"):
tab.actions.click("@id=delete_mail")
time.sleep(1)
if tab.ele("@id=confirm_mail"):
tab.actions.click("@id=confirm_mail")