seleniumselenium-webdriverselenium-chromedrivercloudflarebypass

Selenium: How can I bypass Cloudflare


I want to connect to a site with Webdriver, but cloudflare challenge(not hcaptcha) detects selenium as a bot and doesnt pass me through the Cloudflare challenge.

I have used these flags and many similar flags in my code, but I have not been able to bypass yet.

    ChromeOptions options=new ChromeOptions();
    options.setExperimentalOption("excludeSwitches", Collections.singletonList("enable-automation"));
    options.setExperimentalOption("useAutomationExtension", false);
    options.addArguments("--disable-blink-features");
    options.addArguments("--disable-blink-features=AutomationControlled");
    System.setProperty("webdriver.chrome.driver", "drivers/chromedriver.exe");
    driver = new ChromeDriver(options);

My chrome version 104.0.5112.81 and chrome driver version is 104.0.5112.79

How can I bypass Cloudflare?


Solution

  • To bypass cloudflare you need a high score here https://antcpt.com/score_detector/ (green) , this is for reCaptcha but is relevant for cloudflare too i think. Here are some things other that flags you want to try:

    1. Do not use a VPN or TOR , VPN if its paid it can be good but if you use TOR the last node is always public (i am not sure about that , but you cant bypass cloudflare if you use tor)
    2. I dont see in your code if you are changing user agent... i used selenium_stealth in python to change user agent , renderer and such
     stealth(driver,
                languages=["en-US", "en"],
                vendor="Google Inc.",
                platform="Win32",
                webgl_vendor="Intel Inc.",
                renderer="Intel Iris OpenGL Engine",
                fix_hairline=True,
                )
    

    here is another link to test your driver on https://intoli.com/blog/making-chrome-headless-undetectable/chrome-headless-test.html (there was one with more features but i dont remember the link...)

    __ 3. You probably would need to use an existing profile , so it doesnt seem like you are a bot , your current one with a lot of cookies and other data would be good (i am not sure if this actually works , but when in practice it seemed for me that it helped) here is a link to how to load one... How to load default profile in Chrome using Python Selenium Webdriver?

    __ 4. Remove the flag from chromedriver.exe $cdc_

    __ 5. Probably check this too Can a website detect when you are using Selenium with chromedriver?

    Also note that bypassing cloudflare too much will worsen your score if the website will detect bot behaviour.