-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcursor_pro_keep.py
More file actions
329 lines (279 loc) · 10.4 KB
/
Copy pathcursor_pro_keep.py
File metadata and controls
329 lines (279 loc) · 10.4 KB
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
# https://linux.do/t/topic/267034 让白嫖 Cursor 更优雅一些
from DrissionPage import ChromiumOptions, Chromium
from DrissionPage.common import Keys
import re
import time
import random
def get_veri_code(tab):
"""获取验证码"""
username = account.split('@')[0]
try:
while True:
if tab.ele('@id=pre_button'):
tab.actions.click('@id=pre_button').type(Keys.CTRL_A).key_down(Keys.BACKSPACE).key_up(Keys.BACKSPACE).input(username).key_down(Keys.ENTER).key_up(Keys.ENTER)
break
time.sleep(1)
while True:
new_mail = tab.ele('@class=mail')
if new_mail:
if new_mail.text:
print('最新的邮件:', new_mail.text)
tab.actions.click('@class=mail')
break
else:
print(new_mail)
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('验证码:', code)
else:
print('未找到验证码')
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')
print("删除邮件")
tab.close()
except Exception as e:
print(e)
return code
def handle_turnstile(tab):
"""处理 Turnstile 验证"""
print("准备处理验证")
try:
while True:
try:
challengeCheck = (tab.ele('@id=cf-turnstile', timeout=2)
.child()
.shadow_root
.ele("tag:iframe")
.ele("tag:body")
.sr("tag:input"))
if challengeCheck:
print("验证框加载完成")
time.sleep(random.uniform(1, 3))
challengeCheck.click()
print("验证按钮已点击,等待验证完成...")
time.sleep(2)
return True
except:
pass
if tab.ele('@name=password'):
print("无需验证")
break
if tab.ele('@data-index=0'):
print("无需验证")
break
if tab.ele('Account Settings'):
print("无需验证")
break
time.sleep(random.uniform(1,2))
except Exception as e:
print(e)
print('跳过验证')
return False
def delete_account(browser, tab):
"""删除账户流程"""
print("\n开始删除账户...")
try:
if tab.ele('@name=email'):
tab.ele('@name=email').input(account)
print("输入账号")
time.sleep(random.uniform(1,3))
except Exception as e:
print(f"输入账号失败: {str(e)}")
try:
if tab.ele('Continue'):
tab.ele('Continue').click()
print("点击Continue")
except Exception as e:
print(f"点击Continue失败: {str(e)}")
handle_turnstile(tab)
time.sleep(5)
try:
if tab.ele('@name=password'):
tab.ele('@name=password').input(password)
print("输入密码")
time.sleep(random.uniform(1,3))
except Exception as e:
print("输入密码失败")
sign_in_button = tab.ele('xpath:/html/body/div[1]/div/div/div[2]/div/form/div/button')
try:
if sign_in_button:
sign_in_button.click(by_js=True)
print("点击Sign in")
except Exception as e:
print(f"点击Sign in失败: {str(e)}")
handle_turnstile(tab)
# 处理验证码
while True:
try:
if tab.ele('Account Settings'):
break
if tab.ele('@data-index=0'):
tab_mail = browser.new_tab(mail_url)
browser.activate_tab(tab_mail)
print("打开邮箱页面")
code = get_veri_code(tab_mail)
if code:
print("获取验证码成功:", code)
browser.activate_tab(tab)
else:
print("获取验证码失败,程序退出")
return False
i = 0
for digit in code:
tab.ele(f'@data-index={i}').input(digit)
time.sleep(random.uniform(0.1,0.3))
i += 1
break
except Exception as e:
print(e)
handle_turnstile(tab)
time.sleep(random.uniform(1,3))
# tab.get_screenshot('sign-in_success.png')
# print("登录账户截图")
tab.get('https://www.cursor.com/settings')
print("进入设置页面")
try:
if tab.ele('@class=mt-1'):
tab.ele('@class=mt-1').click()
print("点击Adavance")
time.sleep(random.uniform(1,2))
except Exception as e:
print(f"点击Adavance失败: {str(e)}")
try:
if tab.ele('Delete Account'):
tab.ele('Delete Account').click()
print("点击Delete Account")
time.sleep(random.uniform(1,2))
except Exception as e:
print(f"点击Delete Account失败: {str(e)}")
try:
if tab.ele('tag:input'):
tab.actions.click('tag:input').type('delete')
print("输入delete")
time.sleep(random.uniform(1,2))
except Exception as e:
print(f"输入delete失败: {str(e)}")
delete_button = tab.ele('xpath:/html/body/main/div/div/div/div/div/div[1]/div[2]/div[3]/div[2]/div/div/div[2]/button[2]')
try:
if delete_button:
print("点击Delete")
delete_button.click()
time.sleep(5)
# tab.get_screenshot('delete_account.png')
# print("删除账户截图")
return True
except Exception as e:
print(f"点击Delete失败: {str(e)}")
return False
def sign_up_account(browser, tab):
"""注册账户流程"""
print("\n开始注册新账户...")
tab.get(sign_up_url)
try:
if tab.ele('@name=first_name'):
print("已打开注册页面")
tab.actions.click('@name=first_name').input(first_name)
time.sleep(random.uniform(1,3))
tab.actions.click('@name=last_name').input(last_name)
time.sleep(random.uniform(1,3))
tab.actions.click('@name=email').input(account)
print("输入邮箱" )
time.sleep(random.uniform(1,3))
tab.actions.click('@type=submit')
print("点击注册按钮")
except Exception as e:
print("打开注册页面失败")
return False
handle_turnstile(tab)
try:
if tab.ele('@name=password'):
tab.ele('@name=password').input(password)
print("输入密码")
time.sleep(random.uniform(1,3))
tab.ele('@type=submit').click()
print("点击Continue按钮")
except Exception as e:
print("输入密码失败")
return False
time.sleep(random.uniform(1,3))
if tab.ele('This email is not available.'):
print('This email is not available.')
return False
handle_turnstile(tab)
while True:
try:
if tab.ele('Account Settings'):
break
if tab.ele('@data-index=0'):
tab_mail = browser.new_tab(mail_url)
browser.activate_tab(tab_mail)
print("打开邮箱页面")
code = get_veri_code(tab_mail)
if code:
print("获取验证码成功:", code)
browser.activate_tab(tab)
else:
print("获取验证码失败,程序退出")
return False
i = 0
for digit in code:
tab.ele(f'@data-index={i}').input(digit)
time.sleep(random.uniform(0.1,0.3))
i += 1
break
except Exception as e:
print(e)
handle_turnstile(tab)
time.sleep(random.uniform(1,3))
# tab.get_screenshot("sign_up_success.png")
# print("注册账户截图")
print("注册完成")
print("Cursor 账号: " + account)
print(" 密码: " + password)
return True
if __name__ == "__main__":
# 配置信息
login_url = 'https://authenticator.cursor.sh'
sign_up_url = 'https://authenticator.cursor.sh/sign-up'
mail_url = 'https://tempmail.plus'
account = 'your_account' #必须是 username@mailto.plus 邮箱
password = 'your_password'
first_name = 'your_firstname'
last_name = 'your_lastname'
# 浏览器配置
co = ChromiumOptions()
co.add_extension("turnstilePatch")
co.headless() #无头模式
co.set_user_agent('Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.6723.92 Safari/537.36')
co.set_pref('credentials_enable_service', False)
co.set_argument('--hide-crash-restore-bubble')
co.auto_port()
# co.set_argument('--no-sandbox') # 无沙盒模式 用于linux
# co.set_argument('--headless=new') #无界面系统启动参数 用于linux
# co.set_proxy('127.0.0.1:10809') #设置代理
browser = Chromium(co)
tab = browser.latest_tab
tab.run_js("try { turnstile.reset() } catch(e) { }")
print("开始执行删除和注册流程")
print("***请确认已经用https://tempmail.plus/zh邮箱成功申请过cursor账号!***")
tab.get(login_url)
# 执行删除和注册流程
if delete_account(browser, tab):
print("账户删除成功")
time.sleep(3)
if sign_up_account(browser, tab):
print("账户注册成功")
else:
print("账户注册失败")
else:
print("账户删除失败")
print("脚本执行完毕")
browser.quit()