Skip to content

Commit aed62a4

Browse files
authored
Merge pull request #3088 from seleniumbase/more-uc-mode-updates
More UC Mode updates
2 parents 70b05ff + f426f9c commit aed62a4

File tree

5 files changed

+46
-6
lines changed

5 files changed

+46
-6
lines changed

examples/raw_cf.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
"""SB Manager using UC Mode & PyAutoGUI for bypassing CAPTCHAs."""
2+
from seleniumbase import SB
3+
4+
with SB(uc=True, test=True) as sb:
5+
url = "https://www.cloudflare.com/login"
6+
sb.uc_open_with_reconnect(url, 5)
7+
sb.uc_gui_handle_captcha() # PyAutoGUI press Tab and Spacebar
8+
sb.sleep(2.5)
9+
10+
with SB(uc=True, test=True) as sb:
11+
url = "https://www.cloudflare.com/login"
12+
sb.uc_open_with_reconnect(url, 5)
13+
sb.uc_gui_click_captcha() # PyAutoGUI click. (Linux needs it)
14+
sb.sleep(2.5)

mkdocs_build/requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ MarkupSafe==2.1.5
1111
Jinja2==3.1.4
1212
click==8.1.7
1313
ghp-import==2.1.0
14-
watchdog==5.0.0
14+
watchdog==5.0.2
1515
cairocffi==1.7.1
1616
pathspec==0.12.1
1717
Babel==2.16.0
@@ -20,7 +20,7 @@ lxml==5.3.0
2020
pyquery==2.0.1
2121
readtime==3.0.0
2222
mkdocs==1.6.1
23-
mkdocs-material==9.5.33
23+
mkdocs-material==9.5.34
2424
mkdocs-exclude-search==0.6.6
2525
mkdocs-simple-hooks==0.1.5
2626
mkdocs-material-extensions==1.3.1

seleniumbase/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# seleniumbase package
2-
__version__ = "4.30.1"
2+
__version__ = "4.30.2"

seleniumbase/core/browser_launcher.py

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,17 +340,19 @@ def find_edgedriver_version_to_use(use_version, driver_version):
340340
return use_version
341341

342342

343-
def has_cf(text):
343+
def has_captcha(text):
344344
if (
345345
"<title>403 Forbidden</title>" in text
346346
or "Permission Denied</title>" in text
347347
or 'id="challenge-error-text"' in text
348348
or "<title>Just a moment..." in text
349349
or 'action="/?__cf_chl_f_tk' in text
350+
or 'id="challenge-widget-' in text
350351
or 'src="chromedriver.js"' in text
351352
or 'class="g-recaptcha"' in text
352353
or 'content="Pixelscan"' in text
353354
or 'id="challenge-form"' in text
355+
or "/challenge-platform" in text
354356
or "window._cf_chl_opt" in text
355357
or "/recaptcha/api.js" in text
356358
or "/turnstile/" in text
@@ -377,7 +379,7 @@ def uc_special_open_if_cf(
377379
status_str.startswith("3")
378380
or status_str.startswith("4")
379381
or status_str.startswith("5")
380-
or has_cf(req_get.text)
382+
or has_captcha(req_get.text)
381383
):
382384
special = True
383385
if status_str == "403" or status_str == "429":
@@ -763,6 +765,8 @@ def _on_a_cf_turnstile_page(driver):
763765
source = driver.get_page_source()
764766
if (
765767
'data-callback="onCaptchaSuccess"' in source
768+
or "/challenge-platform/scripts/" in source
769+
or 'id="challenge-widget-' in source
766770
or "cf-turnstile-" in source
767771
):
768772
return True
@@ -866,6 +870,13 @@ def _uc_gui_click_captcha(
866870
and driver.is_element_present("div.spacer div")
867871
):
868872
frame = "div.spacer div"
873+
elif (
874+
driver.is_element_present('script[src*="challenges.c"]')
875+
and driver.is_element_present(
876+
'[data-testid*="challenge-"] div'
877+
)
878+
):
879+
frame = '[data-testid*="challenge-"] div'
869880
elif (
870881
(
871882
driver.is_element_present('[name*="cf-turnstile-"]')
@@ -883,6 +894,14 @@ def _uc_gui_click_captcha(
883894
)
884895
):
885896
frame = "%s .cf-turnstile-wrapper" % frame
897+
elif (
898+
frame != "iframe"
899+
and driver.is_element_present(
900+
'%s [name*="cf-turnstile"]' % frame
901+
)
902+
and driver.is_element_present("%s div" % frame)
903+
):
904+
frame = "%s div" % frame
886905
elif driver.is_element_present(".cf-turnstile-wrapper"):
887906
frame = ".cf-turnstile-wrapper"
888907
elif driver.is_element_present(
@@ -1102,6 +1121,13 @@ def _uc_gui_handle_captcha(
11021121
and driver.is_element_present("div.spacer div")
11031122
):
11041123
frame = "div.spacer div"
1124+
elif (
1125+
driver.is_element_present('script[src*="challenges.c"]')
1126+
and driver.is_element_present(
1127+
'[data-testid*="challenge-"] div'
1128+
)
1129+
):
1130+
frame = '[data-testid*="challenge-"] div'
11051131
elif (
11061132
(
11071133
driver.is_element_present('[name*="cf-turnstile-"]')

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@
263263
'pdfminer.six==20221105;python_version<"3.8"',
264264
'pdfminer.six==20240706;python_version>="3.8"',
265265
'cryptography==39.0.2;python_version<"3.9"',
266-
'cryptography==43.0.0;python_version>="3.9"',
266+
'cryptography==43.0.1;python_version>="3.9"',
267267
'cffi==1.15.1;python_version<"3.8"',
268268
'cffi==1.17.0;python_version>="3.8"',
269269
"pycparser==2.22",

0 commit comments

Comments
 (0)