ultrafunkamsterdam / undetected-chromedriver

Custom Selenium Chromedriver | Zero-Config | Passes ALL bot mitigation systems (like Distil / Imperva/ Datadadome / CloudFlare IUAM)
https://github.com/UltrafunkAmsterdam/undetected-chromedriver
GNU General Public License v3.0
9.07k stars 1.09k forks source link

I can't bypass cloudflare #1579

Open mcsham opened 9 months ago

mcsham commented 9 months ago
from time import sleep

from selenium.common import TimeoutException
from selenium.webdriver.support import expected_conditions as EC
import undetected_chromedriver as uc  # the driver
from selenium.webdriver.common.by import By  # to find various items on the page
from selenium.webdriver.chrome.options import Options  # to have devtools open
from selenium.webdriver.support.wait import WebDriverWait
from undetected_chromedriver import WebElement

def wait_elem(driver, selector, m=EC.presence_of_element_located, method=By.XPATH, tmt=5,
              click=False) -> WebElement | None:
    try:
        el = WebDriverWait(driver, tmt).until(m((method, selector)))
        if click and el:
            el.click()
        return el
    except TimeoutException:
        return None
    except Exception as f:
        print(f)
        return None

def cloudflare(driver):
    for _ in range(5):
        if not any([i in driver.page_source for i in ['site connection is secure', 'are a human']]):
            return False
        iframe = wait_elem(driver, 'iframe[src *= "cloudflare.com"]', tmt=15, method=By.CSS_SELECTOR)
        if not iframe:
            return False
        driver.switch_to.frame(iframe)
        cb = wait_elem(driver, 'input[type=checkbox]', method=By.CSS_SELECTOR)
        if cb:
            cb.click()
        driver.switch_to.default_content()
        sleep(3)

if __name__ == '__main__':
    url = 'https://www.propertyguru.com.sg/property-for-sale?agent_id=195876&market=residential'
    options = Options()
    options.add_argument('--auto-open-devtools-for-tabs')
    driver = uc.Chrome(options=options, use_subprocess=True)
    driver.execute_script(f'window.open("{url}", "_blank");')
    driver.switch_to.window(driver.window_handles[-1])
    cloudflare(driver)
    sleep(10)
    driver.quit()  # quit

What am I doing wrong?

zaimatest commented 9 months ago

Have you solved this problem?

zaimatest commented 9 months ago

I gave it a try, it seems to be possible

mcsham commented 9 months ago

Ви вирішили цю проблему?

Not yet. Even if you go from the home page, it doesn't let you through until you create a new tab by hand. And then after a couple of pages it blocks.

FujiwaraChoki commented 6 months ago

Weird, it worked for me.