Hana Celeste commited on
Commit
fb00487
·
verified ·
1 Parent(s): 5f390e2

Update app/aternos_api.py

Browse files
Files changed (1) hide show
  1. app/aternos_api.py +13 -44
app/aternos_api.py CHANGED
@@ -1,7 +1,6 @@
1
- import os
2
- os.environ["PLAYWRIGHT_BROWSERS_PATH"] = "0"
3
  import asyncio
4
- from undetected_playwright.async_api import async_playwright
 
5
 
6
  class AternosAPI:
7
  def __init__(self):
@@ -19,55 +18,25 @@ class AternosAPI:
19
  async def check_access(self):
20
  if not self.playwright: await self.start()
21
 
22
- # Dùng trình duyệt ẩn danh hoàn toàn
23
  browser = await self.playwright.chromium.launch(
24
  headless=True,
25
  proxy=self.proxy_config,
26
- args=["--no-sandbox", "--disable-setuid-sandbox", "--disable-blink-features=AutomationControlled"]
27
  )
28
-
29
- context = await browser.new_context(
30
- user_agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36",
31
- viewport={'width': 1920, 'height': 1080}
32
- )
33
-
34
- # MẸO CỐT LÕI: Ghi đè webdriver để qua mặt Cloudflare
35
- await context.add_init_script("""
36
- Object.defineProperty(navigator, 'webdriver', {get: () => undefined});
37
- window.chrome = { runtime: {} };
38
- """)
39
-
40
  page = await context.new_page()
41
-
 
 
 
42
  try:
43
- # Truy cập trang chủ trước
44
- await page.goto("https://aternos.org/go/", wait_until="commit", timeout=60000)
45
-
46
- # Đợi thử thách Cloudflare biến mất
47
- print("[INFO] Đang đợi thử thách Cloudflare...")
48
- for _ in range(20): # Tăng lên 20 giây cho chắc
49
- title = await page.title()
50
- if "Just a moment" not in title:
51
- break
52
- await asyncio.sleep(1)
53
 
54
- # Thử click vào một chỗ trống để trigger tương tác người thật
55
- await page.mouse.click(100, 100)
56
- await asyncio.sleep(2)
57
-
58
- # Lấy thông tin cuối cùng
59
  title = await page.title()
60
- content = await page.content()
61
-
62
- # Nếu title là "Login..." nghĩa là đã VƯỢT QUA CLOUDFLARE thành công
63
- is_cf_gone = "Just a moment" not in title
64
-
65
- return {
66
- "ok": is_cf_gone,
67
- "title": title,
68
- "msg": "Vượt Cloudflare thành công!" if is_cf_gone else "Vẫn bị kẹt"
69
- }
70
-
71
  except Exception as e:
72
  return {"ok": False, "error": str(e)}
73
  finally:
 
 
 
1
  import asyncio
2
+ from playwright.async_api import async_playwright
3
+ from playwright_stealth import stealth_async
4
 
5
  class AternosAPI:
6
  def __init__(self):
 
18
  async def check_access(self):
19
  if not self.playwright: await self.start()
20
 
21
+ # Mở browser từ playwright gốc
22
  browser = await self.playwright.chromium.launch(
23
  headless=True,
24
  proxy=self.proxy_config,
25
+ args=["--no-sandbox", "--disable-blink-features=AutomationControlled"]
26
  )
27
+ context = await browser.new_context(user_agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36")
 
 
 
 
 
 
 
 
 
 
 
28
  page = await context.new_page()
29
+
30
+ # Tàng hình
31
+ await stealth_async(page)
32
+
33
  try:
34
+ await page.goto("https://aternos.org/go/", wait_until="networkidle", timeout=60000)
35
+ # Chờ 10s cho Cloudflare
36
+ await asyncio.sleep(10)
 
 
 
 
 
 
 
37
 
 
 
 
 
 
38
  title = await page.title()
39
+ return {"ok": "Just a moment" not in title, "title": title}
 
 
 
 
 
 
 
 
 
 
40
  except Exception as e:
41
  return {"ok": False, "error": str(e)}
42
  finally: