| |
| import asyncio |
| import time |
| from playwright.async_api import async_playwright |
|
|
|
|
| class ClLqApp: |
| def __init__(self): |
| self.url = "https://tangacc.net" |
| self.browser = None |
| self.pw = None |
| self.semaphore = asyncio.Semaphore(10) |
|
|
| async def start(self): |
| self.pw = await async_playwright().start() |
|
|
| self.browser = await self.pw.chromium.launch( |
| headless=True, |
| args=[ |
| "--no-sandbox", |
| "--disable-setuid-sandbox", |
| "--disable-blink-features=AutomationControlled", |
| "--disable-dev-shm-usage", |
| "--disable-gpu", |
| "--disable-extensions" |
| ] |
| ) |
|
|
| async def stop(self): |
| if self.browser: |
| await self.browser.close() |
| if self.pw: |
| await self.pw.stop() |
|
|
| async def fetch_acc(self): |
| async with self.semaphore: |
| start_time = time.perf_counter() |
|
|
| context = await self.browser.new_context( |
| user_agent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Safari/605.1.15", |
| viewport={"width": 1280, "height": 720}, |
| locale="en-US", |
| timezone_id="Asia/Ho_Chi_Minh", |
| java_script_enabled=True, |
| ignore_https_errors=True |
| ) |
|
|
| await context.route( |
| "**/*", |
| lambda route: route.abort() |
| if route.request.resource_type in ["image", "stylesheet", "font", "media"] |
| else route.continue_() |
| ) |
|
|
| page = await context.new_page() |
|
|
| try: |
| await page.goto( |
| self.url, |
| wait_until="domcontentloaded", |
| timeout=15000 |
| ) |
|
|
| await page.click("#getBtn") |
|
|
| await page.wait_for_selector( |
| "#usernameField:not(:has-text('—'))", |
| timeout=10000 |
| ) |
|
|
| username = await page.text_content("#usernameField") |
| password = await page.text_content("#passwordField") |
|
|
| processed_time = round(time.perf_counter() - start_time, 1) |
|
|
| return { |
| "ok": True, |
| "account": { |
| "username": username.strip(), |
| "password": password.strip() |
| }, |
| "processed": f"{processed_time}s" |
| } |
|
|
| except Exception as e: |
| processed_time = round(time.perf_counter() - start_time, 1) |
|
|
| return { |
| "ok": False, |
| "error": str(e), |
| "processed": f"{processed_time}s" |
| } |
|
|
| finally: |
| await context.close() |