diff options
author | Heiner Lohaus <hlohaus@users.noreply.github.com> | 2024-01-27 02:00:44 +0100 |
---|---|---|
committer | Heiner Lohaus <hlohaus@users.noreply.github.com> | 2024-01-27 02:00:44 +0100 |
commit | 47b50b4827121ec68d9e52a018b631a4a3f09625 (patch) | |
tree | d4d9d2040f8588634413be86d7e24b914fa6e29c /g4f/webdriver.py | |
parent | Fix: ChromeDriver only supports characters in the BMP (diff) | |
download | gpt4free-47b50b4827121ec68d9e52a018b631a4a3f09625.tar gpt4free-47b50b4827121ec68d9e52a018b631a4a3f09625.tar.gz gpt4free-47b50b4827121ec68d9e52a018b631a4a3f09625.tar.bz2 gpt4free-47b50b4827121ec68d9e52a018b631a4a3f09625.tar.lz gpt4free-47b50b4827121ec68d9e52a018b631a4a3f09625.tar.xz gpt4free-47b50b4827121ec68d9e52a018b631a4a3f09625.tar.zst gpt4free-47b50b4827121ec68d9e52a018b631a4a3f09625.zip |
Diffstat (limited to '')
-rw-r--r-- | g4f/webdriver.py | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/g4f/webdriver.py b/g4f/webdriver.py index 66b3956e..ee03ff66 100644 --- a/g4f/webdriver.py +++ b/g4f/webdriver.py @@ -13,7 +13,8 @@ try: except ImportError: from typing import Type as WebDriver has_requirements = False - + +import time from os import path from os import access, R_OK from .errors import MissingRequirementsError @@ -92,7 +93,27 @@ def bypass_cloudflare(driver: WebDriver, url: str, timeout: int) -> None: if driver.find_element(By.TAG_NAME, "body").get_attribute("class") == "no-js": if debug.logging: print("Cloudflare protection detected:", url) + + # Open website in a new tab + element = driver.find_element(By.ID, "challenge-body-text") + driver.execute_script(f""" + arguments[0].addEventListener('click', () => {{ + window.open(arguments[1]); + }}); + """, element, url) + element.click() + time.sleep(3) + + # Switch to the new tab and close the old tab + original_window = driver.current_window_handle + for window_handle in driver.window_handles: + if window_handle != original_window: + driver.close() + driver.switch_to.window(window_handle) + break + try: + # Click on the challenge button in the iframe driver.switch_to.frame(driver.find_element(By.CSS_SELECTOR, "#turnstile-wrapper iframe")) WebDriverWait(driver, 5).until( EC.presence_of_element_located((By.CSS_SELECTOR, "#challenge-stage input")) |