import aiohttp import asyncio import re import random class GrassRest: def __init__(self, email: str, password: str, user_agent: str = None, proxy: str = None): self.email = email self.password = password self.user_agent = user_agent self.proxy = proxy self.website_headers = { 'authority': 'api.getgrass.io', 'accept': 'application/json, text/plain, */*', 'accept-language': 'uk-UA,uk;q=0.9,en-US;q=0.8,en;q=0.7', 'content-type': 'application/json', 'origin': 'https://app.getgrass.io', 'referer': 'https://app.getgrass.io/', 'sec-ch-ua': '"Not_A Brand";v="8", "Chromium";v="120", "Google Chrome";v="120"', 'sec-ch-ua-mobile': '?0', 'sec-ch-ua-platform': '"Windows"', 'sec-fetch-dest': 'empty', 'sec-fetch-mode': 'cors', 'sec-fetch-site': 'same-site', 'user-agent': self.user_agent, } self.session = None async def login(self): url = 'https://api.getgrass.io/login' json_data = { 'password': self.password, 'username': self.email, } async with self.session.post(url, headers=self.website_headers, json=json_data, proxy=self.proxy) as response: if response.status != 200: raise Exception(f"Login failed for {self.email}: {await response.text()}") return await response.json() async def enter_account(self): res_json = await self.login() self.website_headers['Authorization'] = res_json['result']['data']['accessToken'] return res_json['result']['data']['userId'] async def main(): # 账号列表 account_list = [ 'jack0210_@hotmail.com', 'yujiec0210@gmail.com', 'yujieccyj01@hotmail.com', 'yujieccyj02@hotmail.com', 'yujieccyj03@hotmail.com', 'yujieccyj04@hotmail.com', 'yujieccyj05@hotmail.com', 'yujieccyj06@hotmail.com', 'yujieccyj07@hotmail.com', 'yujieccyj08@hotmail.com', 'yujieccyj09@hotmail.com', 'yujieccyj10@hotmail.com', 'yujieccyj11@hotmail.com' ] # 密码(假设所有账号的密码相同,如果不同请自行修改) password = "aaaAAA111!!!" user_agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36" proxy = None # 如果需要代理,可以设置代理地址 async with aiohttp.ClientSession() as session: tasks = [] for email in account_list: grass_rest = GrassRest(email, password, user_agent, proxy) grass_rest.session = session tasks.append(grass_rest.enter_account()) user_ids = await asyncio.gather(*tasks, return_exceptions=True) with open("account.txt", "w") as f: for email, user_id in zip(account_list, user_ids): if isinstance(user_id, Exception): print(f"{email}: Error - {user_id}") else: print(f"{email}: {user_id}") f.write(f"{user_id}\n") print("UserID 获取完成,已保存到 account.txt 文件中。") if __name__ == "__main__": asyncio.run(main())