import os
import sys
import time
import random
from datetime import datetime
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import NoSuchElementException, TimeoutException
class ChatGPTMembershipChecker:
def __init__(self):
self.driver = None
self.wait = None
def setup_driver(self):
"""Setup Chrome driver with anti-detection measures"""
chrome_options = Options()
# Anti-detection options
chrome_options.add_argument("--no-sandbox")
chrome_options.add_argument("--disable-dev-shm-usage")
chrome_options.add_argument("--disable-blink-features=AutomationControlled")
chrome_options.add_experimental_option("excludeSwitches", ["enable-automation"])
chrome_options.add_experimental_option('useAutomationExtension', False)
# Window size
chrome_options.add_argument("--window-size=1920,1080")
# User agent
user_agents = [
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
]
chrome_options.add_argument(f"user-agent={random.choice(user_agents)}")
# Initialize driver
self.driver = webdriver.Chrome(options=chrome_options)
self.driver.execute_script("Object.defineProperty(navigator, 'webdriver', {get: () => undefined})")
self.driver.execute_script("window.chrome.runtime = {};")
self.wait = WebDriverWait(self.driver, 10)
def parse_netscape_cookies(self, cookie_file_path):
"""Parse Netscape format cookie file"""
cookies = []
try:
with open(cookie_file_path, 'r', encoding='utf-8') as f:
lines = f.readlines()
for line in lines:
line = line.strip()
if not line or line.startswith('#'):
continue
parts = line.split('\t')
if len(parts) >= 7:
cookie = {
'domain': parts[0],
'path': parts[2],
'secure': parts[3].upper() == 'TRUE',
'expiry': int(parts[4]) if parts[4].isdigit() else None,
'name': parts[5],
'value': parts[6]
}
# Filter for ChatGPT/OpenAI domains
if any(domain in cookie['domain'] for domain in ['chatgpt.com', 'openai.com']):
cookies.append(cookie)
except Exception as e:
print(f"❌ Error parsing cookie file: {e}")
return None
return cookies
def load_cookies(self, cookies):
"""Load cookies into browser"""
self.driver.get("https://chatgpt.com")
for cookie in cookies:
try:
# Remove domain prefix if present
if cookie['domain'].startswith('.'):
cookie['domain'] = cookie['domain'][1:]
self.driver.add_cookie(cookie)
except Exception as e:
continue
# Refresh to apply cookies
self.driver.refresh()
def bypass_cloudflare(self):
"""Attempt to bypass Cloudflare protection"""
max_attempts = 3
for attempt in range(max_attempts):
print(f"🛡️ Cloudflare bypass attempt {attempt + 1}/{max_attempts}")
# Wait strategy
time.sleep(30)
# Check if CF protection is active
page_source = self.driver.page_source.lower()
cf_indicators = ['checking your browser', 'cloudflare', 'ray id', 'just a moment']
if not any(indicator in page_source for indicator in cf_indicators):
return True
# Refresh strategy
self.driver.refresh()
time.sleep(5)
# Click strategy - look for verification buttons
try:
verify_buttons = self.driver.find_elements(By.CSS_SELECTOR,
"[data-testid='challenge-stage'], .cf-turnstile-wrapper, .verify-button")
for button in verify_buttons:
if button.is_displayed():
button.click()
time.sleep(3)
return