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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import time
|
| 2 |
+
import json
|
| 3 |
+
import logging
|
| 4 |
+
from selenium import webdriver
|
| 5 |
+
from selenium.webdriver.common.by import By
|
| 6 |
+
from selenium.webdriver.support.ui import WebDriverWait
|
| 7 |
+
from selenium.webdriver.support import expected_conditions as EC
|
| 8 |
+
from selenium.webdriver.chrome.options import Options
|
| 9 |
+
from selenium.webdriver.chrome.service import Service
|
| 10 |
+
|
| 11 |
+
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
| 12 |
+
logger = logging.getLogger(__name__)
|
| 13 |
+
|
| 14 |
+
class HCaptchaSolver:
|
| 15 |
+
def __init__(self):
|
| 16 |
+
self.driver = None
|
| 17 |
+
self.wait = None
|
| 18 |
+
self.setup_driver()
|
| 19 |
+
|
| 20 |
+
def setup_driver(self):
|
| 21 |
+
chrome_options = Options()
|
| 22 |
+
chrome_options.add_argument('--no-sandbox')
|
| 23 |
+
chrome_options.add_argument('--disable-dev-shm-usage')
|
| 24 |
+
chrome_options.add_argument('--disable-gpu')
|
| 25 |
+
chrome_options.add_argument('--disable-software-rasterizer')
|
| 26 |
+
chrome_options.add_argument('--disable-dev-tools')
|
| 27 |
+
chrome_options.add_argument('--no-zygote')
|
| 28 |
+
chrome_options.add_argument('--single-process')
|
| 29 |
+
chrome_options.add_argument('--window-size=1920,1080')
|
| 30 |
+
chrome_options.add_argument('--headless=new')
|
| 31 |
+
chrome_options.add_argument('--disable-blink-features=AutomationControlled')
|
| 32 |
+
chrome_options.add_experimental_option("excludeSwitches", ["enable-automation"])
|
| 33 |
+
chrome_options.add_experimental_option('useAutomationExtension', False)
|
| 34 |
+
chrome_options.add_argument('user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36')
|
| 35 |
+
|
| 36 |
+
self.driver = webdriver.Chrome(options=chrome_options)
|
| 37 |
+
self.wait = WebDriverWait(self.driver, 30)
|
| 38 |
+
|
| 39 |
+
self.driver.execute_cdp_cmd('Page.addScriptToEvaluateOnNewDocument', {
|
| 40 |
+
'source': '''
|
| 41 |
+
Object.defineProperty(navigator, 'webdriver', {get: () => undefined});
|
| 42 |
+
Object.defineProperty(navigator, 'plugins', {get: () => [1, 2, 3, 4, 5]});
|
| 43 |
+
Object.defineProperty(navigator, 'languages', {get: () => ['en-US', 'en']});
|
| 44 |
+
window.chrome = {runtime: {}};
|
| 45 |
+
'''
|
| 46 |
+
})
|
| 47 |
+
|
| 48 |
+
logger.info("Chrome driver setup complete")
|
| 49 |
+
|
| 50 |
+
def open_page(self):
|
| 51 |
+
logger.info("Opening bylo.ai...")
|
| 52 |
+
self.driver.get("https://bylo.ai/features/sora-2")
|
| 53 |
+
time.sleep(3)
|
| 54 |
+
|
| 55 |
+
def click_login_button(self):
|
| 56 |
+
logger.info("Clicking login button...")
|
| 57 |
+
login_btn = self.wait.until(
|
| 58 |
+
EC.element_to_be_clickable((By.CSS_SELECTOR, 'button.flex.items-center.gap-3'))
|
| 59 |
+
)
|
| 60 |
+
login_btn.click()
|
| 61 |
+
time.sleep(2)
|
| 62 |
+
|
| 63 |
+
def click_signup(self):
|
| 64 |
+
logger.info("Clicking Sign Up...")
|
| 65 |
+
signup = self.wait.until(
|
| 66 |
+
EC.element_to_be_clickable((By.XPATH, "//span[text()='Sign Up']"))
|
| 67 |
+
)
|
| 68 |
+
signup.click()
|
| 69 |
+
time.sleep(2)
|
| 70 |
+
|
| 71 |
+
def fill_email(self, email):
|
| 72 |
+
logger.info(f"Filling email: {email}")
|
| 73 |
+
email_input = self.wait.until(
|
| 74 |
+
EC.presence_of_element_located((By.CSS_SELECTOR, 'input[name="email"]'))
|
| 75 |
+
)
|
| 76 |
+
email_input.clear()
|
| 77 |
+
email_input.send_keys(email)
|
| 78 |
+
time.sleep(1)
|
| 79 |
+
|
| 80 |
+
def click_get_code(self):
|
| 81 |
+
logger.info("Clicking Get Code...")
|
| 82 |
+
get_code = self.wait.until(
|
| 83 |
+
EC.element_to_be_clickable((By.XPATH, "//button[text()='Get Code']"))
|
| 84 |
+
)
|
| 85 |
+
get_code.click()
|
| 86 |
+
time.sleep(3)
|
| 87 |
+
|
| 88 |
+
def solve_hcaptcha_auto(self):
|
| 89 |
+
logger.info("Starting hCaptcha auto solve...")
|
| 90 |
+
|
| 91 |
+
time.sleep(3)
|
| 92 |
+
|
| 93 |
+
iframes = self.driver.find_elements(By.TAG_NAME, 'iframe')
|
| 94 |
+
logger.info(f"Found {len(iframes)} iframes")
|
| 95 |
+
|
| 96 |
+
for idx, iframe in enumerate(iframes):
|
| 97 |
+
try:
|
| 98 |
+
iframe_src = iframe.get_attribute('src')
|
| 99 |
+
|
| 100 |
+
if iframe_src and 'hcaptcha.com/captcha' in iframe_src:
|
| 101 |
+
logger.info(f"Found hCaptcha iframe at index {idx}")
|
| 102 |
+
|
| 103 |
+
self.driver.switch_to.frame(iframe)
|
| 104 |
+
time.sleep(2)
|
| 105 |
+
|
| 106 |
+
try:
|
| 107 |
+
checkbox = self.wait.until(
|
| 108 |
+
EC.element_to_be_clickable((By.CSS_SELECTOR, '#checkbox'))
|
| 109 |
+
)
|
| 110 |
+
logger.info("Clicking checkbox...")
|
| 111 |
+
checkbox.click()
|
| 112 |
+
time.sleep(3)
|
| 113 |
+
|
| 114 |
+
self.driver.switch_to.default_content()
|
| 115 |
+
time.sleep(3)
|
| 116 |
+
|
| 117 |
+
token = self.get_hcaptcha_token()
|
| 118 |
+
if token:
|
| 119 |
+
return token
|
| 120 |
+
|
| 121 |
+
except Exception as e:
|
| 122 |
+
logger.warning(f"Checkbox not found in this iframe: {e}")
|
| 123 |
+
self.driver.switch_to.default_content()
|
| 124 |
+
|
| 125 |
+
except Exception as e:
|
| 126 |
+
logger.warning(f"Error processing iframe {idx}: {e}")
|
| 127 |
+
self.driver.switch_to.default_content()
|
| 128 |
+
|
| 129 |
+
logger.info("Trying JavaScript bypass...")
|
| 130 |
+
|
| 131 |
+
bypass_script = """
|
| 132 |
+
var response = document.querySelector('[name="h-captcha-response"]');
|
| 133 |
+
if (response && response.value) {
|
| 134 |
+
return response.value;
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
if (window.hcaptcha) {
|
| 138 |
+
try {
|
| 139 |
+
var widgetID = window.hcaptcha.render(document.querySelector('.h-captcha'));
|
| 140 |
+
window.hcaptcha.execute(widgetID);
|
| 141 |
+
} catch(e) {}
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
return null;
|
| 145 |
+
"""
|
| 146 |
+
|
| 147 |
+
for attempt in range(15):
|
| 148 |
+
result = self.driver.execute_script(bypass_script)
|
| 149 |
+
if result:
|
| 150 |
+
logger.info("Token obtained from JavaScript bypass!")
|
| 151 |
+
return result
|
| 152 |
+
|
| 153 |
+
time.sleep(2)
|
| 154 |
+
logger.info(f"Bypass attempt {attempt + 1}/15")
|
| 155 |
+
|
| 156 |
+
logger.info("Waiting for token to appear...")
|
| 157 |
+
for i in range(40):
|
| 158 |
+
token = self.get_hcaptcha_token()
|
| 159 |
+
if token:
|
| 160 |
+
return token
|
| 161 |
+
time.sleep(1)
|
| 162 |
+
|
| 163 |
+
return None
|
| 164 |
+
|
| 165 |
+
def get_hcaptcha_token(self):
|
| 166 |
+
try:
|
| 167 |
+
token = self.driver.execute_script("""
|
| 168 |
+
var elements = [
|
| 169 |
+
document.querySelector('textarea[name="h-captcha-response"]'),
|
| 170 |
+
document.querySelector('[data-hcaptcha-response]'),
|
| 171 |
+
document.querySelector('input[name="h-captcha-response"]')
|
| 172 |
+
];
|
| 173 |
+
|
| 174 |
+
for (var el of elements) {
|
| 175 |
+
if (el && el.value) {
|
| 176 |
+
return el.value;
|
| 177 |
+
}
|
| 178 |
+
if (el && el.getAttribute('data-hcaptcha-response')) {
|
| 179 |
+
return el.getAttribute('data-hcaptcha-response');
|
| 180 |
+
}
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
return null;
|
| 184 |
+
""")
|
| 185 |
+
|
| 186 |
+
if token and len(token) > 10:
|
| 187 |
+
logger.info(f"TOKEN FOUND: {token[:50]}...")
|
| 188 |
+
logger.info(f"Token length: {len(token)}")
|
| 189 |
+
return token
|
| 190 |
+
|
| 191 |
+
except Exception as e:
|
| 192 |
+
pass
|
| 193 |
+
|
| 194 |
+
return None
|
| 195 |
+
|
| 196 |
+
def run(self, email="herzfnf@gmail.com"):
|
| 197 |
+
try:
|
| 198 |
+
self.open_page()
|
| 199 |
+
self.click_login_button()
|
| 200 |
+
self.click_signup()
|
| 201 |
+
self.fill_email(email)
|
| 202 |
+
self.click_get_code()
|
| 203 |
+
|
| 204 |
+
token = self.solve_hcaptcha_auto()
|
| 205 |
+
|
| 206 |
+
if token:
|
| 207 |
+
logger.info("SUCCESS! Token retrieved")
|
| 208 |
+
return {
|
| 209 |
+
"success": True,
|
| 210 |
+
"token": token,
|
| 211 |
+
"email": email
|
| 212 |
+
}
|
| 213 |
+
else:
|
| 214 |
+
logger.warning("Failed to get token")
|
| 215 |
+
return {
|
| 216 |
+
"success": False,
|
| 217 |
+
"message": "Failed to get hCaptcha token"
|
| 218 |
+
}
|
| 219 |
+
|
| 220 |
+
except Exception as e:
|
| 221 |
+
logger.error(f"Error: {e}")
|
| 222 |
+
return {
|
| 223 |
+
"success": False,
|
| 224 |
+
"error": str(e)
|
| 225 |
+
}
|
| 226 |
+
|
| 227 |
+
def cleanup(self):
|
| 228 |
+
if self.driver:
|
| 229 |
+
self.driver.quit()
|
| 230 |
+
logger.info("Browser closed")
|
| 231 |
+
|
| 232 |
+
if __name__ == "__main__":
|
| 233 |
+
solver = HCaptchaSolver()
|
| 234 |
+
try:
|
| 235 |
+
result = solver.run("herzfnf@gmail.com")
|
| 236 |
+
print("\n" + "="*60)
|
| 237 |
+
print("RESULT:")
|
| 238 |
+
print(json.dumps(result, indent=2))
|
| 239 |
+
print("="*60)
|
| 240 |
+
finally:
|
| 241 |
+
solver.cleanup()
|