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.71k stars 1.14k forks source link

need a solution to bypass cloudflare instead of having to open devtool #1400

Open NCLnclNCL opened 1 year ago

NCLnclNCL commented 1 year ago

...devtool open gives me some errors

kit1858644 commented 1 year ago

devtool method no longer works for me.

ghost commented 1 year ago

devtool method no longer works for me.

same, however solution one does still work for bypassing cloudflare

NCLnclNCL commented 1 year ago

devtool method no longer works for me.

same, however solution one does still work for bypassing cloudflare

Solutions 1 not working with me

ParhamSobhan commented 1 year ago

it stopped working since 12h ago :x

matthewransley commented 1 year ago

After close analysis. It seems that they detect if you use the first tab entirely. Simply launch the instance on the first tab, wait 5 seconds then open another one and close the first one. Now that second one will be entirely undetected for the rest of the instances life.

luluhoc commented 1 year ago

After close analysis. It seems that they detect if you use the first tab entirely. Simply launch the instance on the first tab, wait 5 seconds then open another one and close the first one. Now that second one will be entirely undetected for the rest of the instances life.

@epicmatthew23 Do you know how to do it with puppeteer?

syxme commented 1 year ago

After close analysis. It seems that they detect if you use the first tab entirely. Simply launch the instance on the first tab, wait 5 seconds then open another one and close the first one. Now that second one will be entirely undetected for the rest of the instances life.

@epicmatthew23 Do you know how to do it with puppeteer?

Did you succeed?

MarioRogue commented 1 year ago

@epicmatthew23 Code snippet?

Hudrolax commented 1 year ago

This code works for me:

import undetected_chromedriver as uc
import os
from time import sleep

current_dir = os.getcwd()
target_url = 'https://nowsecure.nl'
with open('blank.html', 'w') as f:
    f.write(f'<a href="{target_url}" target="_blank">link</a>')

driver = uc.Chrome(headless=True, use_subprocess=False)
driver.get(f'file://{current_dir}/blank.html')
links = driver.find_elements(By.XPATH, "//a[@href]")
sleep(10)
links[0].click()
sleep(5)
driver.switch_to.window(driver.window_handles[1])
driver.save_screenshot('nowsecure.png')

I dont know why, but it doesn't work without sleep.

vanni11 commented 1 year ago

devtools option or opening a new tab doesn't work for me neither. Is there any other solution to this cloudflare problem?

+) opening a new tab is working well now I increased seconds in time.sleep()

IAISI commented 1 year ago

They just pushed new update around 2023-07-19 17:00 GMT+2

I think they're detecting chromedriver somehow... can click on turnstile forever via API or manually when launched via chromedriver...

BGP0 commented 1 year ago

My solution

My old code:

driver.execute_script("window.open('https://someprotectedwebsite', '_blank')")
driver.switch_to.window(driver.window_handles[1])

My new code:

driver.execute_script("window.open('https://someprotectedwebsite', '_blank')")
+ sleep(15)
driver.switch_to.window(driver.window_handles[1])

If you call the switch_to_window() while cloudflare is checking the browser, it will get detected So simple solution is just wait a few seconds for cloudflare to load before switching to the window :)

greathope commented 1 year ago

refresh will lead to block again, any idea?

luluhoc commented 1 year ago

refresh will lead to block again, any idea?

Yes, if you want to bypass the turnstile within the site it's dead, when selenium touches the tab it's over. Wonder how they are detecting it.

Chikimaro commented 1 year ago

My solution

My old code:

driver.execute_script("window.open('https://someprotectedwebsite', '_blank')")
driver.switch_to.window(driver.window_handles[1])

My new code:

driver.execute_script("window.open('https://someprotectedwebsite', '_blank')")
+ sleep(15)
driver.switch_to.window(driver.window_handles[1])

If you call the switch_to_window() while cloudflare is checking the browser, it will get detected So simple solution is just wait a few seconds for cloudflare to load before switching to the window :)

works for me, thx

Hudrolax commented 1 year ago

Try to use sleep() as in my example.

NCLnclNCL commented 1 year ago

Try to use sleep() as in my example.

but if cloudflare has checkbox you can't pass it

bear102 commented 1 year ago

Try to use sleep() as in my example.

but if cloudflare has checkbox you can't pass it

Try this it worked for me.

import undetected_chromedriver as uc

chrome_options = uc.ChromeOptions() chrome_options.add_argument("--disable-popup-blocking")

driver = uc.Chrome(options=chrome_options)

url = 'https://nowsecure.nl/' driver.get(url) driver.execute_script(f"window.open('{url}', '_blank')") input()

mdmintz commented 1 year ago

If your issue is related to Chrome 115, then according to https://github.com/SeleniumHQ/selenium/milestone/12, the earliest that the fix will be available in selenium is sometime next week.

Until then, you can use SeleniumBase's UC Mode as an alternative, which has the fix for Chrome 115.

First pip install seleniumbase, and then run the following script with python:

from seleniumbase import Driver
import time

driver = Driver(uc=True)
driver.get("https://nowsecure.nl/#relax")
time.sleep(8)
driver.quit()

Once selenium gets a new release, undetected-chromedriver can pull that in and make updates as necessary.

IAISI commented 1 year ago

Aside from warning... it works just fine


jul. 21, 2023 3:57:08 DOP. org.openqa.selenium.devtools.CdpVersionFinder findNearestMatch
WARNING: Unable to find an exact match for CDP version 115, so returning the closest version found: 113```
ParhamSobhan commented 1 year ago

pip install seleniumbase

If your issue is related to Chrome 115, then according to https://github.com/SeleniumHQ/selenium/milestone/12, the earliest that the fix will be available in selenium is sometime next week.

Until then, you can use SeleniumBase's UC Mode as an alternative, which has the fix for Chrome 115.

First pip install seleniumbase, and then run the following script with python:

from seleniumbase import Driver
import time

driver = Driver(uc=True)
driver.get("https://nowsecure.nl/#relax")
time.sleep(8)
driver.quit()

Once selenium gets a new release, undetected-chromedriver can pull that in and make updates as necessary.

there is a problem when it download the driver for the first time and open the website it bypasses the cf but second time it get stock!

ParhamSobhan commented 1 year ago

If your issue is related to Chrome 115, then according to https://github.com/SeleniumHQ/selenium/milestone/12, the earliest that the fix will be available in selenium is sometime next week.

Until then, you can use SeleniumBase's UC Mode as an alternative, which has the fix for Chrome 115.

First pip install seleniumbase, and then run the following script with python:

from seleniumbase import Driver
import time

driver = Driver(uc=True)
driver.get("https://nowsecure.nl/#relax")
time.sleep(8)
driver.quit()

Once selenium gets a new release, undetected-chromedriver can pull that in and make updates as necessary.

the problem is when you open 2 script at the same time the second one sucks and if you don't close the first one with driver.quit() all other scripts gonna stock and you have to close the uc_driver.exe from task manager before running other script. SO THIS CODE SUCKS

mdmintz commented 1 year ago

If you're not going to close the driver yourself at the end of your script with driver.quit(), then use the seleniumbase context manager format instead, which does that for you:

import time
from seleniumbase import DriverContext

with DriverContext(uc=True) as driver:
    driver.get("https://nowsecure.nl/#relax")
    time.sleep(6)

Only one script like that can be run at the same time. (Single-threaded only!)

Once you start performing any selenium actions on the page, (such as clicking, switching to a tab, or executing javascript), websites can detect selenium (as of today). Maybe pyautogui can help with undetected clicking, etc.

Pilaton commented 1 year ago

To prevent CF from blocking your automation, you need to hide the CDP session from it. You can check this by disabling CDP in an already running browser. The captcha will immediately let you through, even if you are already on the page with it.

Motivationking commented 1 year ago

soo you find any way to CDP session?

SavageCore commented 3 months ago

FYI, seleniumbase's SB mode works a treat at the moment.

Example implementation: https://github.com/KlevGG/TrackerScreenshot/pull/3/commits/12fceea25807347697dc8bfa454435f0da3f6a62

AftabHussainShar commented 2 months ago

Selenium Script for Bypassing Cloudflare

This Python script utilizes undetected_chromedriver to interact with a webpage and bypass Cloudflare. It demonstrates how to handle a webpage that may have Cloudflare protection by navigating through a series of steps and taking a screenshot. Below is an overview and explanation of the script:

Script Overview

  1. Setup:

    • Imports necessary libraries and sets up the environment.
    • Creates a local HTML file (blank.html) containing a link to a target URL.
  2. Driver Initialization:

    • Initializes a headless Chrome browser using undetected_chromedriver.
  3. Navigation:

    • Opens the local HTML file containing the link to the target URL.
    • Waits for the link to be clickable and then clicks it.

Script


import undetected_chromedriver as uc
import os
from time import sleep
from selenium.webdriver.common.by import By

current_dir = os.getcwd()
target_url = 'https://nowsecure.nl'
with open('blank.html', 'w') as f:
    f.write(f'<a href="{target_url}" target="_blank">link</a>')

driver = uc.Chrome(headless=True, use_subprocess=False)
driver.get(f'file://{current_dir}/blank.html')
links = driver.find_elements(By.XPATH, "//a[@href]")
sleep(10)
links[0].click()
sleep(5)
driver.switch_to.window(driver.window_handles[1])
driver.save_screenshot('nowsecure.png')