2024-12-28 20:05:29 +08:00
|
|
|
|
import os
|
2024-12-28 20:34:34 +08:00
|
|
|
|
|
2025-01-09 18:53:34 +08:00
|
|
|
|
from exit_cursor import ExitCursor
|
2025-01-10 18:17:37 +08:00
|
|
|
|
from reset_machine import MachineIDResetter
|
2025-01-09 18:53:34 +08:00
|
|
|
|
|
2024-12-28 20:34:34 +08:00
|
|
|
|
os.environ["PYTHONVERBOSE"] = "0"
|
|
|
|
|
|
os.environ["PYINSTALLER_VERBOSE"] = "0"
|
2024-12-28 20:05:29 +08:00
|
|
|
|
|
2024-12-28 15:14:40 +08:00
|
|
|
|
import time
|
|
|
|
|
|
import random
|
|
|
|
|
|
from cursor_auth_manager import CursorAuthManager
|
|
|
|
|
|
import os
|
2025-01-09 13:01:01 +08:00
|
|
|
|
from logger import logging
|
2024-12-28 21:56:48 +08:00
|
|
|
|
from browser_utils import BrowserManager
|
2025-01-03 18:41:28 +08:00
|
|
|
|
from get_email_code import EmailVerificationHandler
|
2025-01-04 09:38:26 +08:00
|
|
|
|
from logo import print_logo
|
2025-01-10 19:33:45 +08:00
|
|
|
|
from config import Config
|
2024-12-28 15:14:40 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def handle_turnstile(tab):
|
2025-01-03 16:13:43 +08:00
|
|
|
|
print("开始突破难关")
|
2024-12-28 15:14:40 +08:00
|
|
|
|
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:
|
2025-01-03 16:13:43 +08:00
|
|
|
|
print("开始突破")
|
2024-12-28 15:14:40 +08:00
|
|
|
|
time.sleep(random.uniform(1, 3))
|
|
|
|
|
|
challengeCheck.click()
|
|
|
|
|
|
time.sleep(2)
|
2025-01-03 16:13:43 +08:00
|
|
|
|
print("突破成功")
|
2024-12-28 15:14:40 +08:00
|
|
|
|
return True
|
|
|
|
|
|
except:
|
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
if tab.ele("@name=password"):
|
2025-01-03 16:13:43 +08:00
|
|
|
|
print("突破成功")
|
2024-12-28 15:14:40 +08:00
|
|
|
|
break
|
|
|
|
|
|
if tab.ele("@data-index=0"):
|
2025-01-03 16:13:43 +08:00
|
|
|
|
print("突破成功")
|
2024-12-28 15:14:40 +08:00
|
|
|
|
break
|
|
|
|
|
|
if tab.ele("Account Settings"):
|
2025-01-03 16:13:43 +08:00
|
|
|
|
print("突破成功")
|
2024-12-28 15:14:40 +08:00
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
|
|
time.sleep(random.uniform(1, 2))
|
|
|
|
|
|
except Exception as e:
|
|
|
|
|
|
print(e)
|
2025-01-03 16:13:43 +08:00
|
|
|
|
print("突破失败")
|
2024-12-28 15:14:40 +08:00
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-12-31 16:41:59 +08:00
|
|
|
|
def get_cursor_session_token(tab, max_attempts=3, retry_interval=2):
|
|
|
|
|
|
"""
|
|
|
|
|
|
获取Cursor会话token,带有重试机制
|
|
|
|
|
|
:param tab: 浏览器标签页
|
|
|
|
|
|
:param max_attempts: 最大尝试次数
|
|
|
|
|
|
:param retry_interval: 重试间隔(秒)
|
|
|
|
|
|
:return: session token 或 None
|
|
|
|
|
|
"""
|
2024-12-31 13:21:07 +08:00
|
|
|
|
print("开始获取cookie")
|
2024-12-31 16:41:59 +08:00
|
|
|
|
attempts = 0
|
|
|
|
|
|
|
|
|
|
|
|
while attempts < max_attempts:
|
|
|
|
|
|
try:
|
|
|
|
|
|
cookies = tab.cookies()
|
|
|
|
|
|
for cookie in cookies:
|
|
|
|
|
|
if cookie.get("name") == "WorkosCursorSessionToken":
|
|
|
|
|
|
return cookie["value"].split("%3A%3A")[1]
|
|
|
|
|
|
|
|
|
|
|
|
attempts += 1
|
|
|
|
|
|
if attempts < max_attempts:
|
|
|
|
|
|
print(
|
|
|
|
|
|
f"第 {attempts} 次尝试未获取到CursorSessionToken,{retry_interval}秒后重试..."
|
|
|
|
|
|
)
|
|
|
|
|
|
time.sleep(retry_interval)
|
|
|
|
|
|
else:
|
|
|
|
|
|
print(f"已达到最大尝试次数({max_attempts}),获取CursorSessionToken失败")
|
|
|
|
|
|
|
|
|
|
|
|
except Exception as e:
|
|
|
|
|
|
print(f"获取cookie失败: {str(e)}")
|
|
|
|
|
|
attempts += 1
|
|
|
|
|
|
if attempts < max_attempts:
|
|
|
|
|
|
print(f"将在 {retry_interval} 秒后重试...")
|
|
|
|
|
|
time.sleep(retry_interval)
|
|
|
|
|
|
|
|
|
|
|
|
return None
|
2024-12-28 15:14:40 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def update_cursor_auth(email=None, access_token=None, refresh_token=None):
|
|
|
|
|
|
"""
|
|
|
|
|
|
更新Cursor的认证信息的便捷函数
|
|
|
|
|
|
"""
|
|
|
|
|
|
auth_manager = CursorAuthManager()
|
|
|
|
|
|
return auth_manager.update_auth(email, access_token, refresh_token)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def sign_up_account(browser, tab):
|
2025-01-03 16:13:43 +08:00
|
|
|
|
print("开始执行...")
|
2024-12-28 15:14:40 +08:00
|
|
|
|
tab.get(sign_up_url)
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
if tab.ele("@name=first_name"):
|
|
|
|
|
|
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)
|
|
|
|
|
|
time.sleep(random.uniform(1, 3))
|
|
|
|
|
|
|
|
|
|
|
|
tab.actions.click("@type=submit")
|
|
|
|
|
|
|
|
|
|
|
|
except Exception as e:
|
|
|
|
|
|
print("打开注册页面失败")
|
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
handle_turnstile(tab)
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
if tab.ele("@name=password"):
|
|
|
|
|
|
tab.ele("@name=password").input(password)
|
|
|
|
|
|
time.sleep(random.uniform(1, 3))
|
|
|
|
|
|
|
|
|
|
|
|
tab.ele("@type=submit").click()
|
2025-01-03 16:13:43 +08:00
|
|
|
|
print("请稍等...")
|
2024-12-28 15:14:40 +08:00
|
|
|
|
|
|
|
|
|
|
except Exception as e:
|
2025-01-03 16:13:43 +08:00
|
|
|
|
print("执行失败")
|
2024-12-28 15:14:40 +08:00
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
time.sleep(random.uniform(1, 3))
|
|
|
|
|
|
if tab.ele("This email is not available."):
|
2025-01-03 16:13:43 +08:00
|
|
|
|
print("执行失败")
|
2024-12-28 15:14:40 +08:00
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
handle_turnstile(tab)
|
|
|
|
|
|
|
|
|
|
|
|
while True:
|
|
|
|
|
|
try:
|
|
|
|
|
|
if tab.ele("Account Settings"):
|
|
|
|
|
|
break
|
|
|
|
|
|
if tab.ele("@data-index=0"):
|
2024-12-28 21:56:48 +08:00
|
|
|
|
code = email_handler.get_verification_code(account)
|
2024-12-31 16:26:09 +08:00
|
|
|
|
if not code:
|
2024-12-28 15:14:40 +08:00
|
|
|
|
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)
|
2024-12-31 17:03:53 +08:00
|
|
|
|
wait_time = random.randint(3, 6)
|
|
|
|
|
|
for i in range(wait_time):
|
|
|
|
|
|
print(f"等待中... {wait_time-i}秒")
|
|
|
|
|
|
time.sleep(1)
|
2024-12-28 15:14:40 +08:00
|
|
|
|
tab.get(settings_url)
|
|
|
|
|
|
try:
|
2024-12-30 23:16:45 +08:00
|
|
|
|
usage_selector = (
|
|
|
|
|
|
"css:div.col-span-2 > div > div > div > div > "
|
|
|
|
|
|
"div:nth-child(1) > div.flex.items-center.justify-between.gap-2 > "
|
|
|
|
|
|
"span.font-mono.text-sm\\/\\[0\\.875rem\\]"
|
2024-12-28 15:14:40 +08:00
|
|
|
|
)
|
2024-12-30 23:16:45 +08:00
|
|
|
|
usage_ele = tab.ele(usage_selector)
|
2024-12-28 15:14:40 +08:00
|
|
|
|
if usage_ele:
|
|
|
|
|
|
usage_info = usage_ele.text
|
|
|
|
|
|
total_usage = usage_info.split("/")[-1].strip()
|
|
|
|
|
|
print("可用上限: " + total_usage)
|
|
|
|
|
|
except Exception as e:
|
|
|
|
|
|
print("获取可用上限失败")
|
|
|
|
|
|
print("注册完成")
|
2025-01-03 11:40:31 +08:00
|
|
|
|
account_info = f"\nCursor 账号: {account} 密码: {password}"
|
|
|
|
|
|
logging.info(account_info)
|
2024-12-30 23:16:45 +08:00
|
|
|
|
time.sleep(5)
|
2024-12-28 15:14:40 +08:00
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-12-30 23:16:45 +08:00
|
|
|
|
class EmailGenerator:
|
|
|
|
|
|
def __init__(
|
|
|
|
|
|
self,
|
|
|
|
|
|
password="".join(
|
|
|
|
|
|
random.choices(
|
|
|
|
|
|
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*",
|
|
|
|
|
|
k=12,
|
|
|
|
|
|
)
|
|
|
|
|
|
),
|
|
|
|
|
|
first_name="yuyan",
|
|
|
|
|
|
last_name="peng",
|
|
|
|
|
|
):
|
2025-01-10 19:33:45 +08:00
|
|
|
|
self.domain = Config().get_domain()
|
2024-12-30 23:16:45 +08:00
|
|
|
|
self.default_password = password
|
|
|
|
|
|
self.default_first_name = first_name
|
|
|
|
|
|
self.default_last_name = last_name
|
|
|
|
|
|
|
|
|
|
|
|
def generate_email(self, length=8):
|
|
|
|
|
|
"""生成随机邮箱地址"""
|
|
|
|
|
|
random_str = "".join(random.choices("abcdefghijklmnopqrstuvwxyz", k=length))
|
|
|
|
|
|
timestamp = str(int(time.time()))[-6:] # 使用时间戳后6位
|
|
|
|
|
|
return f"{random_str}{timestamp}@{self.domain}"
|
|
|
|
|
|
|
|
|
|
|
|
def get_account_info(self):
|
|
|
|
|
|
"""获取完整的账号信息"""
|
|
|
|
|
|
return {
|
|
|
|
|
|
"email": self.generate_email(),
|
|
|
|
|
|
"password": self.default_password,
|
|
|
|
|
|
"first_name": self.default_first_name,
|
|
|
|
|
|
"last_name": self.default_last_name,
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-12-28 15:14:40 +08:00
|
|
|
|
if __name__ == "__main__":
|
2025-01-04 09:38:26 +08:00
|
|
|
|
print_logo()
|
2024-12-28 21:56:48 +08:00
|
|
|
|
browser_manager = None
|
2024-12-28 15:14:40 +08:00
|
|
|
|
try:
|
2025-01-09 18:53:34 +08:00
|
|
|
|
ExitCursor()
|
2024-12-28 21:56:48 +08:00
|
|
|
|
# 初始化浏览器
|
|
|
|
|
|
browser_manager = BrowserManager()
|
|
|
|
|
|
browser = browser_manager.init_browser()
|
|
|
|
|
|
|
2024-12-30 23:16:45 +08:00
|
|
|
|
# 初始化邮箱验证处理器
|
2024-12-28 21:56:48 +08:00
|
|
|
|
email_handler = EmailVerificationHandler(browser)
|
|
|
|
|
|
|
2024-12-28 15:14:40 +08:00
|
|
|
|
# 固定的 URL 配置
|
|
|
|
|
|
login_url = "https://authenticator.cursor.sh"
|
|
|
|
|
|
sign_up_url = "https://authenticator.cursor.sh/sign-up"
|
|
|
|
|
|
settings_url = "https://www.cursor.com/settings"
|
|
|
|
|
|
mail_url = "https://tempmail.plus"
|
|
|
|
|
|
|
2024-12-30 23:16:45 +08:00
|
|
|
|
# 生成随机邮箱
|
|
|
|
|
|
email_generator = EmailGenerator()
|
|
|
|
|
|
account = email_generator.generate_email()
|
|
|
|
|
|
password = email_generator.default_password
|
|
|
|
|
|
first_name = email_generator.default_first_name
|
|
|
|
|
|
last_name = email_generator.default_last_name
|
2024-12-28 15:14:40 +08:00
|
|
|
|
|
|
|
|
|
|
auto_update_cursor_auth = True
|
|
|
|
|
|
|
|
|
|
|
|
tab = browser.latest_tab
|
|
|
|
|
|
tab.run_js("try { turnstile.reset() } catch(e) { }")
|
|
|
|
|
|
|
|
|
|
|
|
tab.get(login_url)
|
|
|
|
|
|
|
2024-12-30 23:16:45 +08:00
|
|
|
|
if sign_up_account(browser, tab):
|
|
|
|
|
|
token = get_cursor_session_token(tab)
|
2024-12-31 16:26:09 +08:00
|
|
|
|
if token:
|
2024-12-30 23:16:45 +08:00
|
|
|
|
update_cursor_auth(
|
|
|
|
|
|
email=account, access_token=token, refresh_token=token
|
|
|
|
|
|
)
|
2025-01-10 18:17:37 +08:00
|
|
|
|
|
|
|
|
|
|
MachineIDResetter().reset_machine_ids()
|
2024-12-28 15:14:40 +08:00
|
|
|
|
else:
|
|
|
|
|
|
print("账户注册失败")
|
|
|
|
|
|
|
2025-01-03 16:13:43 +08:00
|
|
|
|
print("执行完毕")
|
2024-12-28 15:14:40 +08:00
|
|
|
|
|
|
|
|
|
|
except Exception as e:
|
2024-12-28 21:56:48 +08:00
|
|
|
|
logging.error(f"程序执行出错: {str(e)}")
|
2024-12-28 20:05:29 +08:00
|
|
|
|
import traceback
|
2024-12-28 20:34:34 +08:00
|
|
|
|
|
2024-12-28 21:56:48 +08:00
|
|
|
|
logging.error(traceback.format_exc())
|
2024-12-28 20:05:29 +08:00
|
|
|
|
finally:
|
2024-12-28 21:56:48 +08:00
|
|
|
|
if browser_manager:
|
|
|
|
|
|
browser_manager.quit()
|
2024-12-28 15:14:40 +08:00
|
|
|
|
input("\n按回车键退出...")
|