From 974731063bc6b218c915e7a07e22e6f5633ac3bc Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Wed, 4 Sep 2024 00:40:43 -0400 Subject: [PATCH 1/4] Update UC Mode --- seleniumbase/core/browser_launcher.py | 30 +++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/seleniumbase/core/browser_launcher.py b/seleniumbase/core/browser_launcher.py index ded68fb9047..9e41ed3d9cd 100644 --- a/seleniumbase/core/browser_launcher.py +++ b/seleniumbase/core/browser_launcher.py @@ -340,17 +340,19 @@ def find_edgedriver_version_to_use(use_version, driver_version): return use_version -def has_cf(text): +def has_captcha(text): if ( "403 Forbidden" in text or "Permission Denied" in text or 'id="challenge-error-text"' in text or "Just a moment..." in text or 'action="/?__cf_chl_f_tk' in text + or 'id="challenge-widget-' in text or 'src="chromedriver.js"' in text or 'class="g-recaptcha"' in text or 'content="Pixelscan"' in text or 'id="challenge-form"' in text + or "/challenge-platform" in text or "window._cf_chl_opt" in text or "/recaptcha/api.js" in text or "/turnstile/" in text @@ -377,7 +379,7 @@ def uc_special_open_if_cf( status_str.startswith("3") or status_str.startswith("4") or status_str.startswith("5") - or has_cf(req_get.text) + or has_captcha(req_get.text) ): special = True if status_str == "403" or status_str == "429": @@ -763,6 +765,8 @@ def _on_a_cf_turnstile_page(driver): source = driver.get_page_source() if ( 'data-callback="onCaptchaSuccess"' in source + or "/challenge-platform/scripts/" in source + or 'id="challenge-widget-' in source or "cf-turnstile-" in source ): return True @@ -866,6 +870,13 @@ def _uc_gui_click_captcha( and driver.is_element_present("div.spacer div") ): frame = "div.spacer div" + elif ( + driver.is_element_present('script[src*="challenges.c"]') + and driver.is_element_present( + '[data-testid*="challenge-"] div' + ) + ): + frame = '[data-testid*="challenge-"] div' elif ( ( driver.is_element_present('[name*="cf-turnstile-"]') @@ -883,6 +894,14 @@ def _uc_gui_click_captcha( ) ): frame = "%s .cf-turnstile-wrapper" % frame + elif ( + frame != "iframe" + and driver.is_element_present( + '%s [name*="cf-turnstile"]' % frame + ) + and driver.is_element_present("%s div" % frame) + ): + frame = "%s div" % frame elif driver.is_element_present(".cf-turnstile-wrapper"): frame = ".cf-turnstile-wrapper" elif driver.is_element_present( @@ -1102,6 +1121,13 @@ def _uc_gui_handle_captcha( and driver.is_element_present("div.spacer div") ): frame = "div.spacer div" + elif ( + driver.is_element_present('script[src*="challenges.c"]') + and driver.is_element_present( + '[data-testid*="challenge-"] div' + ) + ): + frame = '[data-testid*="challenge-"] div' elif ( ( driver.is_element_present('[name*="cf-turnstile-"]') From 4a598ac2de614ad12ff8341c2bdb918e9d68a348 Mon Sep 17 00:00:00 2001 From: Michael Mintz <mdmintz@gmail.com> Date: Wed, 4 Sep 2024 00:41:16 -0400 Subject: [PATCH 2/4] Refresh Python dependencies --- mkdocs_build/requirements.txt | 4 ++-- setup.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/mkdocs_build/requirements.txt b/mkdocs_build/requirements.txt index 6e18547b9d3..22c596a7931 100644 --- a/mkdocs_build/requirements.txt +++ b/mkdocs_build/requirements.txt @@ -11,7 +11,7 @@ MarkupSafe==2.1.5 Jinja2==3.1.4 click==8.1.7 ghp-import==2.1.0 -watchdog==5.0.0 +watchdog==5.0.2 cairocffi==1.7.1 pathspec==0.12.1 Babel==2.16.0 @@ -20,7 +20,7 @@ lxml==5.3.0 pyquery==2.0.1 readtime==3.0.0 mkdocs==1.6.1 -mkdocs-material==9.5.33 +mkdocs-material==9.5.34 mkdocs-exclude-search==0.6.6 mkdocs-simple-hooks==0.1.5 mkdocs-material-extensions==1.3.1 diff --git a/setup.py b/setup.py index dbe1eaa1daf..9c13e687615 100755 --- a/setup.py +++ b/setup.py @@ -263,7 +263,7 @@ 'pdfminer.six==20221105;python_version<"3.8"', 'pdfminer.six==20240706;python_version>="3.8"', 'cryptography==39.0.2;python_version<"3.9"', - 'cryptography==43.0.0;python_version>="3.9"', + 'cryptography==43.0.1;python_version>="3.9"', 'cffi==1.15.1;python_version<"3.8"', 'cffi==1.17.0;python_version>="3.8"', "pycparser==2.22", From df1ad4bc062ed3308e7ec33036a7b882b25a7596 Mon Sep 17 00:00:00 2001 From: Michael Mintz <mdmintz@gmail.com> Date: Wed, 4 Sep 2024 00:42:34 -0400 Subject: [PATCH 3/4] Update examples --- examples/raw_cf.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 examples/raw_cf.py diff --git a/examples/raw_cf.py b/examples/raw_cf.py new file mode 100644 index 00000000000..b8a79149773 --- /dev/null +++ b/examples/raw_cf.py @@ -0,0 +1,14 @@ +"""SB Manager using UC Mode & PyAutoGUI for bypassing CAPTCHAs.""" +from seleniumbase import SB + +with SB(uc=True, test=True) as sb: + url = "https://www.cloudflare.com/login" + sb.uc_open_with_reconnect(url, 5) + sb.uc_gui_handle_captcha() # PyAutoGUI press Tab and Spacebar + sb.sleep(2.5) + +with SB(uc=True, test=True) as sb: + url = "https://www.cloudflare.com/login" + sb.uc_open_with_reconnect(url, 5) + sb.uc_gui_click_captcha() # PyAutoGUI click. (Linux needs it) + sb.sleep(2.5) From f426f9c2dd4ea97e0d7882dc303e56c7ab930970 Mon Sep 17 00:00:00 2001 From: Michael Mintz <mdmintz@gmail.com> Date: Wed, 4 Sep 2024 00:42:52 -0400 Subject: [PATCH 4/4] Version 4.30.2 --- seleniumbase/__version__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/seleniumbase/__version__.py b/seleniumbase/__version__.py index f713d164d44..c7124640cc9 100755 --- a/seleniumbase/__version__.py +++ b/seleniumbase/__version__.py @@ -1,2 +1,2 @@ # seleniumbase package -__version__ = "4.30.1" +__version__ = "4.30.2"