# -*- coding: utf-8 -*- import random import time import httpx class GrassClient: def __init__(self, email, password, user_agent, proxy_ip, proxy_api_port, proxy_web_port): self.email = email self.password = password self.user_agent = user_agent self.proxy_ip = proxy_ip self.proxy_api_port = proxy_api_port self.proxy_web_port = proxy_web_port self.session = httpx.Client() def login(self): url = 'https://api.getgrass.io/login' json_data = { 'password': self.password, 'username': self.email, } 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, } for retry in range(5): try: # 使用 httpx 发送 POST 请求 proxy_web_port = random.choice(self.proxy_web_port) proxy = f"{self.proxy_ip}:{proxy_web_port}" proxies = { "http://": f"http://{proxy}", "https://": f"http://{proxy}", } with httpx.Client(proxies=proxies, headers=headers) as client: response = client.post(url, json=json_data) if response.status_code != 200: error_message = response.text raise httpx.RequestError(f"登录失败,状态码 {response.status_code}: {error_message}") data = response.json() userId = data['result']['data']['userId'] return userId except httpx.RequestError as e: print(e) time.sleep(3) def close(self): self.session.close() # 使用示例 def main(): email_list = [ "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" ] proxy_api_port = ["52001", "52002", "52003", "52004", "52005", "52006", "52007", "52008", "52009", "52010", "52011", "52012"] proxy_web_port = ["53001", "53002", "53003", "53004", "53005", "53006", "53007", "53008", "53009", "53010", "53011", "53012"] password = "aaaAAA111!!!" proxy_ip = "192.168.31.201" 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" user_id_list = [] for email in email_list: client = GrassClient(email, password, user_agent, proxy_ip, proxy_api_port, proxy_web_port) try: login_response = client.login() print("userId:", f'{email} - {login_response}') user_id_list.append(login_response) finally: client.close() if user_id_list: with open("account_details.txt", "w") as file: for email, user_id, api_port, web_port in zip(email_list, user_id_list, proxy_api_port, proxy_web_port): file.write(f"{email}|||{user_id}|||{proxy_ip}:{api_port}|||{proxy_ip}:{web_port}\n") # 运行主函数 if __name__ == "__main__": main()