Update 1.py
Browse files
1.py
CHANGED
|
@@ -24,7 +24,7 @@ try:
|
|
| 24 |
except Exception:
|
| 25 |
pass
|
| 26 |
|
| 27 |
-
required_packages = ["aiohttp", "requests", "h2", "uvloop", "aioquic", "beautifulsoup4", "curl_cffi", "scapy", "httpx", "websockets", "redis", "fastapi", "uvicorn", "apscheduler", "pywinauto"]
|
| 28 |
if platform.system() == "Windows":
|
| 29 |
try:
|
| 30 |
import ctypes
|
|
@@ -1963,8 +1963,13 @@ class VPNRotator:
|
|
| 1963 |
|
| 1964 |
|
| 1965 |
def get_playwright_clearance(url: str, identity=None) -> dict:
|
| 1966 |
-
"""حل تحدي Cloudflare باستخدام
|
| 1967 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1968 |
return {}
|
| 1969 |
|
| 1970 |
if not hasattr(get_playwright_clearance, "semaphore"):
|
|
@@ -1972,85 +1977,65 @@ def get_playwright_clearance(url: str, identity=None) -> dict:
|
|
| 1972 |
|
| 1973 |
result_holder = {}
|
| 1974 |
|
| 1975 |
-
def
|
| 1976 |
with get_playwright_clearance.semaphore:
|
| 1977 |
try:
|
| 1978 |
-
|
| 1979 |
-
|
| 1980 |
-
|
| 1981 |
-
|
|
|
|
|
|
|
| 1982 |
headless=True,
|
| 1983 |
-
|
| 1984 |
-
'--disable-gpu',
|
| 1985 |
-
'--no-sandbox',
|
| 1986 |
-
'--disable-dev-shm-usage',
|
| 1987 |
-
'--disable-blink-features=AutomationControlled',
|
| 1988 |
-
'--disable-extensions',
|
| 1989 |
-
'--disable-features=IsolateOrigins,site-per-process',
|
| 1990 |
-
'--disable-setuid-sandbox',
|
| 1991 |
-
]
|
| 1992 |
)
|
| 1993 |
-
|
| 1994 |
-
'viewport': {'width': random.randint(1366, 1920), 'height': random.randint(768, 1080)},
|
| 1995 |
-
'user_agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36',
|
| 1996 |
-
'locale': random.choice(['en-US', 'en-GB', 'fr-FR', 'de-DE']),
|
| 1997 |
-
'timezone_id': random.choice(['America/New_York', 'Europe/London', 'Europe/Paris']),
|
| 1998 |
-
}
|
| 1999 |
-
if identity and getattr(identity, 'proxy', None):
|
| 2000 |
-
context_options['proxy'] = {'server': identity.proxy}
|
| 2001 |
-
context = browser.new_context(**context_options)
|
| 2002 |
-
page = context.new_page()
|
| 2003 |
-
|
| 2004 |
-
# محاكاة حركة الفأرة البشرية
|
| 2005 |
-
page.mouse.move(random.randint(100, 500), random.randint(100, 500))
|
| 2006 |
-
time.sleep(random.uniform(0.5, 1.5))
|
| 2007 |
|
| 2008 |
-
#
|
| 2009 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2010 |
|
| 2011 |
-
#
|
| 2012 |
-
try:
|
| 2013 |
-
page.wait_for_selector("#challenge-running", state="hidden", timeout=10000)
|
| 2014 |
-
except:
|
| 2015 |
-
pass
|
| 2016 |
-
|
| 2017 |
-
# محاكاة تمرير الفأرة
|
| 2018 |
-
for _ in range(random.randint(2, 5)):
|
| 2019 |
-
page.mouse.wheel(0, random.randint(100, 300))
|
| 2020 |
-
time.sleep(random.uniform(0.2, 0.8))
|
| 2021 |
-
|
| 2022 |
-
# جمع الكوكيز بعد الانتهاء
|
| 2023 |
-
cookies = context.cookies()
|
| 2024 |
-
cookie_dict = {c['name']: c['value'] for c in cookies}
|
| 2025 |
if identity and getattr(identity, 'cookie_jar', None):
|
| 2026 |
for c in cookies:
|
| 2027 |
try:
|
| 2028 |
cookie = http.cookiejar.Cookie(
|
| 2029 |
-
version=0, name=c
|
| 2030 |
-
domain=c
|
| 2031 |
-
path=c
|
| 2032 |
-
expires=int(c
|
| 2033 |
discard=False, comment=None, comment_url=None,
|
| 2034 |
-
rest={'HttpOnly': None} if
|
| 2035 |
)
|
| 2036 |
identity.cookie_jar.set_cookie(cookie)
|
| 2037 |
except:
|
| 2038 |
pass
|
|
|
|
| 2039 |
if 'cf_clearance' in cookie_dict:
|
| 2040 |
result_holder['cookies'] = cookie_dict
|
| 2041 |
-
|
| 2042 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2043 |
except Exception as e:
|
| 2044 |
-
# في حال الفشل، نسجل الخطأ ولكن نستمر
|
| 2045 |
-
pass
|
| 2046 |
-
|
| 2047 |
-
# تشغيل الـ thread مع مهلة 25 ثانية (بدلاً من 38)
|
| 2048 |
-
except Exception:
|
| 2049 |
pass
|
| 2050 |
|
| 2051 |
-
t = threading.Thread(target=
|
| 2052 |
t.start()
|
| 2053 |
-
t.join(timeout=
|
| 2054 |
return result_holder
|
| 2055 |
|
| 2056 |
def load_cf_cookies_from_file(domain: str) -> dict:
|
|
@@ -3849,7 +3834,7 @@ class UltimateIntegratedEngine:
|
|
| 3849 |
if self.use_cffi and CURL_CFFI_AVAILABLE:
|
| 3850 |
# On Windows, select() has a hard limit of 512 file descriptors (sockets)
|
| 3851 |
# Creating too many AsyncSessions causes "ValueError: too many file descriptors in select()"
|
| 3852 |
-
for imp in ["
|
| 3853 |
self.cffi_clients.append(cffi_requests.AsyncSession(impersonate=imp, verify=False, timeout=8))
|
| 3854 |
await self._create_httpx_client()
|
| 3855 |
async def _create_httpx_client(self):
|
|
|
|
| 24 |
except Exception:
|
| 25 |
pass
|
| 26 |
|
| 27 |
+
required_packages = ["aiohttp", "requests", "h2", "uvloop", "aioquic", "beautifulsoup4", "curl_cffi", "scapy", "httpx", "websockets", "redis", "fastapi", "uvicorn", "apscheduler", "pywinauto", "nodriver"]
|
| 28 |
if platform.system() == "Windows":
|
| 29 |
try:
|
| 30 |
import ctypes
|
|
|
|
| 1963 |
|
| 1964 |
|
| 1965 |
def get_playwright_clearance(url: str, identity=None) -> dict:
|
| 1966 |
+
"""حل تحدي Cloudflare باستخدام nodriver (أقوى من Playwright العادي)"""
|
| 1967 |
+
import asyncio
|
| 1968 |
+
|
| 1969 |
+
# We will use nodriver instead of playwright
|
| 1970 |
+
try:
|
| 1971 |
+
import nodriver as uc
|
| 1972 |
+
except ImportError:
|
| 1973 |
return {}
|
| 1974 |
|
| 1975 |
if not hasattr(get_playwright_clearance, "semaphore"):
|
|
|
|
| 1977 |
|
| 1978 |
result_holder = {}
|
| 1979 |
|
| 1980 |
+
def _nodriver_worker():
|
| 1981 |
with get_playwright_clearance.semaphore:
|
| 1982 |
try:
|
| 1983 |
+
# nodriver is async, so we need an event loop in this thread
|
| 1984 |
+
loop = asyncio.new_event_loop()
|
| 1985 |
+
asyncio.set_event_loop(loop)
|
| 1986 |
+
|
| 1987 |
+
async def _run_nodriver():
|
| 1988 |
+
browser = await uc.start(
|
| 1989 |
headless=True,
|
| 1990 |
+
browser_args=['--disable-blink-features=AutomationControlled']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1991 |
)
|
| 1992 |
+
page = await browser.get(url)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1993 |
|
| 1994 |
+
# Wait for challenge to pass (max 20s)
|
| 1995 |
+
wait_count = 0
|
| 1996 |
+
cf_cleared = False
|
| 1997 |
+
while wait_count < 20:
|
| 1998 |
+
cookies = await browser.cookies.get_all()
|
| 1999 |
+
if any(c.name == 'cf_clearance' for c in cookies):
|
| 2000 |
+
cf_cleared = True
|
| 2001 |
+
break
|
| 2002 |
+
await asyncio.sleep(1)
|
| 2003 |
+
wait_count += 1
|
| 2004 |
+
|
| 2005 |
+
cookies = await browser.cookies.get_all()
|
| 2006 |
+
cookie_dict = {c.name: c.value for c in cookies}
|
| 2007 |
|
| 2008 |
+
# Update identity cookie jar if present
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2009 |
if identity and getattr(identity, 'cookie_jar', None):
|
| 2010 |
for c in cookies:
|
| 2011 |
try:
|
| 2012 |
cookie = http.cookiejar.Cookie(
|
| 2013 |
+
version=0, name=c.name, value=c.value, port=None, port_specified=False,
|
| 2014 |
+
domain=c.domain, domain_specified=True, domain_initial_dot=c.domain.startswith('.'),
|
| 2015 |
+
path=c.path, path_specified=True, secure=c.secure,
|
| 2016 |
+
expires=int(c.expires) if hasattr(c, 'expires') and c.expires else None,
|
| 2017 |
discard=False, comment=None, comment_url=None,
|
| 2018 |
+
rest={'HttpOnly': None} if hasattr(c, 'http_only') and c.http_only else {}, rfc2109=False
|
| 2019 |
)
|
| 2020 |
identity.cookie_jar.set_cookie(cookie)
|
| 2021 |
except:
|
| 2022 |
pass
|
| 2023 |
+
|
| 2024 |
if 'cf_clearance' in cookie_dict:
|
| 2025 |
result_holder['cookies'] = cookie_dict
|
| 2026 |
+
# Generate a realistic UA
|
| 2027 |
+
result_holder['ua'] = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36'
|
| 2028 |
+
|
| 2029 |
+
await browser.stop()
|
| 2030 |
+
|
| 2031 |
+
loop.run_until_complete(_run_nodriver())
|
| 2032 |
+
loop.close()
|
| 2033 |
except Exception as e:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2034 |
pass
|
| 2035 |
|
| 2036 |
+
t = threading.Thread(target=_nodriver_worker, daemon=True)
|
| 2037 |
t.start()
|
| 2038 |
+
t.join(timeout=30)
|
| 2039 |
return result_holder
|
| 2040 |
|
| 2041 |
def load_cf_cookies_from_file(domain: str) -> dict:
|
|
|
|
| 3834 |
if self.use_cffi and CURL_CFFI_AVAILABLE:
|
| 3835 |
# On Windows, select() has a hard limit of 512 file descriptors (sockets)
|
| 3836 |
# Creating too many AsyncSessions causes "ValueError: too many file descriptors in select()"
|
| 3837 |
+
for imp in ["chrome126"]:
|
| 3838 |
self.cffi_clients.append(cffi_requests.AsyncSession(impersonate=imp, verify=False, timeout=8))
|
| 3839 |
await self._create_httpx_client()
|
| 3840 |
async def _create_httpx_client(self):
|