Hana Celeste commited on
Update app/byps_logic.py
Browse files- app/byps_logic.py +23 -21
app/byps_logic.py
CHANGED
|
@@ -1,12 +1,13 @@
|
|
| 1 |
import asyncio
|
| 2 |
import random
|
| 3 |
from playwright.async_api import async_playwright
|
| 4 |
-
#
|
| 5 |
-
from playwright_stealth import
|
| 6 |
|
| 7 |
class BypsApp:
|
| 8 |
def __init__(self):
|
| 9 |
self.playwright = None
|
|
|
|
| 10 |
self.proxy_config = {
|
| 11 |
"server": "http://p.webshare.io:80",
|
| 12 |
"username": "szusjfnw-rotate",
|
|
@@ -28,6 +29,7 @@ class BypsApp:
|
|
| 28 |
|
| 29 |
browser = None
|
| 30 |
try:
|
|
|
|
| 31 |
browser = await self.playwright.chromium.launch(
|
| 32 |
headless=False,
|
| 33 |
args=[
|
|
@@ -45,30 +47,32 @@ class BypsApp:
|
|
| 45 |
|
| 46 |
page = await context.new_page()
|
| 47 |
|
| 48 |
-
#
|
| 49 |
-
await
|
| 50 |
|
| 51 |
-
print(f"[BYPS] Đang
|
| 52 |
await page.goto(url, wait_until="commit", timeout=60000)
|
| 53 |
|
| 54 |
-
#
|
| 55 |
for i in range(15):
|
| 56 |
-
content = await page.content()
|
| 57 |
title = await page.title()
|
|
|
|
| 58 |
|
| 59 |
if "just a moment" not in title.lower() and "cloudflare" not in content.lower():
|
| 60 |
-
print(
|
| 61 |
break
|
| 62 |
|
| 63 |
-
|
|
|
|
|
|
|
| 64 |
try:
|
| 65 |
-
# Tìm
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
except:
|
| 73 |
pass
|
| 74 |
|
|
@@ -76,14 +80,12 @@ class BypsApp:
|
|
| 76 |
await asyncio.sleep(3)
|
| 77 |
|
| 78 |
await asyncio.sleep(2)
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
# Trả về kết quả
|
| 82 |
-
return {"ok": True, "data": final_content}
|
| 83 |
|
| 84 |
except Exception as e:
|
| 85 |
print(f"[BYPS ERROR] {str(e)}")
|
| 86 |
return {"ok": False, "error": str(e)}
|
| 87 |
finally:
|
| 88 |
if browser:
|
| 89 |
-
await browser.close()
|
|
|
|
| 1 |
import asyncio
|
| 2 |
import random
|
| 3 |
from playwright.async_api import async_playwright
|
| 4 |
+
# Import hàm stealth (hàm này hỗ trợ cả async)
|
| 5 |
+
from playwright_stealth import stealth
|
| 6 |
|
| 7 |
class BypsApp:
|
| 8 |
def __init__(self):
|
| 9 |
self.playwright = None
|
| 10 |
+
# Proxy config của bạn
|
| 11 |
self.proxy_config = {
|
| 12 |
"server": "http://p.webshare.io:80",
|
| 13 |
"username": "szusjfnw-rotate",
|
|
|
|
| 29 |
|
| 30 |
browser = None
|
| 31 |
try:
|
| 32 |
+
# Khởi chạy browser với Xvfb (headless=False)
|
| 33 |
browser = await self.playwright.chromium.launch(
|
| 34 |
headless=False,
|
| 35 |
args=[
|
|
|
|
| 47 |
|
| 48 |
page = await context.new_page()
|
| 49 |
|
| 50 |
+
# Sử dụng await stealth(page) - ĐÂY LÀ DÒNG QUAN TRỌNG
|
| 51 |
+
await stealth(page)
|
| 52 |
|
| 53 |
+
print(f"[BYPS] Đang mở trang: {url}")
|
| 54 |
await page.goto(url, wait_until="commit", timeout=60000)
|
| 55 |
|
| 56 |
+
# Logic vượt Cloudflare (giữ nguyên)
|
| 57 |
for i in range(15):
|
|
|
|
| 58 |
title = await page.title()
|
| 59 |
+
content = await page.content()
|
| 60 |
|
| 61 |
if "just a moment" not in title.lower() and "cloudflare" not in content.lower():
|
| 62 |
+
print("[BYPS] Đã vượt Cloudflare!")
|
| 63 |
break
|
| 64 |
|
| 65 |
+
print(f"[BYPS] Đang chờ giải thử thách... ({i}s)")
|
| 66 |
+
|
| 67 |
+
# Thử click vào checkbox của Turnstile nếu nó hiện ra
|
| 68 |
try:
|
| 69 |
+
# Tìm frame chứa challenge
|
| 70 |
+
for frame in page.frames:
|
| 71 |
+
if "challenge" in frame.url or "turnstile" in frame.url:
|
| 72 |
+
# Click đại vào tâm của iframe đó
|
| 73 |
+
box = await page.locator('iframe[src*="challenge"]').bounding_box()
|
| 74 |
+
if box:
|
| 75 |
+
await page.mouse.click(box['x'] + box['width']/2, box['y'] + box['height']/2)
|
| 76 |
except:
|
| 77 |
pass
|
| 78 |
|
|
|
|
| 80 |
await asyncio.sleep(3)
|
| 81 |
|
| 82 |
await asyncio.sleep(2)
|
| 83 |
+
result = await page.content()
|
| 84 |
+
return {"ok": True, "data": result}
|
|
|
|
|
|
|
| 85 |
|
| 86 |
except Exception as e:
|
| 87 |
print(f"[BYPS ERROR] {str(e)}")
|
| 88 |
return {"ok": False, "error": str(e)}
|
| 89 |
finally:
|
| 90 |
if browser:
|
| 91 |
+
await browser.close()
|