@@ -1823,7 +1823,11 @@ def _on_a_cf_turnstile_page(self, source=None):
18231823 time .sleep (0.2 )
18241824 source = self .get_page_source ()
18251825 if (
1826- 'data-callback="onCaptchaSuccess"' in source
1826+ (
1827+ 'data-callback="onCaptchaSuccess"' in source
1828+ and not 'title="reCAPTCHA"' in source
1829+ and not 'id="recaptcha-token" in source'
1830+ )
18271831 or "/challenge-platform/scripts/" in source
18281832 or 'id="challenge-widget-' in source
18291833 or "challenges.cloudf" in source
@@ -1836,13 +1840,19 @@ def _on_a_g_recaptcha_page(self, source=None):
18361840 if not source or len (source ) < 400 :
18371841 time .sleep (0.2 )
18381842 source = self .get_page_source ()
1843+ self .loop .run_until_complete (self .page .wait (0.1 ))
18391844 if (
1840- 'id="recaptcha-token"' in source
1841- or 'title="reCAPTCHA"' in source
1845+ (
1846+ 'id="recaptcha-token"' in source
1847+ or 'title="reCAPTCHA"' in source
1848+ )
1849+ and self .is_element_visible ('iframe[title="reCAPTCHA"]' )
18421850 ):
1851+ self .loop .run_until_complete (self .page .wait (0.1 ))
18431852 return True
18441853 elif "/recaptcha/api.js" in source :
18451854 time .sleep (1.6 ) # Still loading
1855+ self .loop .run_until_complete (self .page .wait (0.1 ))
18461856 return True
18471857 return False
18481858
@@ -1852,8 +1862,10 @@ def __gui_click_recaptcha(self, use_cdp=False):
18521862 selector = 'iframe[title="reCAPTCHA"]'
18531863 else :
18541864 return
1865+ time .sleep (0.25 )
1866+ self .loop .run_until_complete (self .page .wait ())
1867+ time .sleep (0.25 )
18551868 with suppress (Exception ):
1856- time .sleep (0.08 )
18571869 element_rect = self .get_gui_element_rect (selector , timeout = 1 )
18581870 e_x = element_rect ["x" ]
18591871 e_y = element_rect ["y" ]
@@ -1884,7 +1896,9 @@ def gui_click_captcha(self):
18841896
18851897 def __click_captcha (self , use_cdp = False ):
18861898 """Uses PyAutoGUI unless use_cdp == True"""
1887- self .sleep (0.056 )
1899+ self .sleep (0.075 )
1900+ self .loop .run_until_complete (self .page .wait ())
1901+ self .sleep (0.025 )
18881902 source = self .get_page_source ()
18891903 if self ._on_a_cf_turnstile_page (source ):
18901904 pass
@@ -1894,61 +1908,32 @@ def __click_captcha(self, use_cdp=False):
18941908 else :
18951909 return
18961910 selector = None
1897- if (
1898- self .is_element_present ('[name*="cf-turnstile-"]' )
1899- and self .is_element_present ("#challenge-form div > div" )
1900- ):
1911+ if self .is_element_present ('[class="cf-turnstile"]' ):
1912+ selector = '[class="cf-turnstile"]'
1913+ elif self .is_element_present ("#challenge-form div > div" ):
19011914 selector = "#challenge-form div > div"
1902- elif (
1903- self .is_element_present ('[name*="cf-turnstile-"]' )
1904- and self .is_element_present (
1905- '[style="display: grid;"] div div'
1906- )
1907- ):
1915+ elif self .is_element_present ('[style="display: grid;"] div div' ):
19081916 selector = '[style="display: grid;"] div div'
1909- elif (
1910- self .is_element_present ('[name*="cf-turnstile-"]' )
1911- and self .is_element_present ("[class*=spacer] + div div" )
1912- ):
1917+ elif self .is_element_present ("[class*=spacer] + div div" ):
19131918 selector = '[class*=spacer] + div div'
1914- elif (
1915- self .is_element_present ('[name*="cf-turnstile-"]' )
1916- and self .is_element_present (".spacer div:not([class])" )
1917- ):
1919+ elif self .is_element_present (".spacer div:not([class])" ):
19181920 selector = ".spacer div:not([class])"
1919- elif (
1920- self .is_element_present ('script[src*="challenges.c"]' )
1921- and self .is_element_present (
1922- '[data-testid*="challenge-"] div'
1923- )
1924- ):
1921+ elif self .is_element_present ('[data-testid*="challenge-"] div' ):
19251922 selector = '[data-testid*="challenge-"] div'
1926- elif self .is_element_present (
1927- "div#turnstile-widget div:not([class])"
1928- ):
1923+ elif self .is_element_present ("div#turnstile-widget div:not([class])" ):
19291924 selector = "div#turnstile-widget div:not([class])"
19301925 elif self .is_element_present ("ngx-turnstile div:not([class])" ):
19311926 selector = "ngx-turnstile div:not([class])"
19321927 elif self .is_element_present (
19331928 'form div:not([class]):has(input[name*="cf-turn"])'
19341929 ):
19351930 selector = 'form div:not([class]):has(input[name*="cf-turn"])'
1936- elif (
1937- self .is_element_present ('[src*="/turnstile/"]' )
1938- and self .is_element_present ("form div:not(:has(*))" )
1939- ):
1931+ elif self .is_element_present ("form div:not(:has(*))" ):
19401932 selector = "form div:not(:has(*))"
1941- elif (
1942- self .is_element_present ('[src*="/turnstile/"]' )
1943- and self .is_element_present (
1944- "body > div#check > div:not([class])"
1945- )
1946- ):
1933+ elif self .is_element_present ("body > div#check > div:not([class])" ):
19471934 selector = "body > div#check > div:not([class])"
19481935 elif self .is_element_present (".cf-turnstile-wrapper" ):
19491936 selector = ".cf-turnstile-wrapper"
1950- elif self .is_element_present ('[class="cf-turnstile"]' ):
1951- selector = '[class="cf-turnstile"]'
19521937 elif self .is_element_present (
19531938 '[id*="turnstile"] div:not([class])'
19541939 ):
@@ -2048,7 +2033,7 @@ def __click_captcha(self, use_cdp=False):
20482033 self .loop .run_until_complete (self .page .evaluate (script ))
20492034 self .loop .run_until_complete (self .page .wait ())
20502035 with suppress (Exception ):
2051- time .sleep (0.08 )
2036+ time .sleep (0.05 )
20522037 element_rect = self .get_gui_element_rect (selector , timeout = 1 )
20532038 e_x = element_rect ["x" ]
20542039 e_y = element_rect ["y" ]
@@ -2059,15 +2044,17 @@ def __click_captcha(self, use_cdp=False):
20592044 x = e_x + x_offset
20602045 y = e_y + y_offset
20612046 sb_config ._saved_cf_x_y = (x , y )
2062- time .sleep (0.08 )
2047+ time .sleep (0.05 )
2048+ if hasattr (sb_config , "_cdp_proxy" ) and sb_config ._cdp_proxy :
2049+ time .sleep (0.22 ) # CAPTCHA may load slower with proxy
20632050 if use_cdp :
20642051 self .sleep (0.03 )
20652052 gui_lock = FileLock (constants .MultiBrowser .PYAUTOGUILOCK )
20662053 with gui_lock : # Prevent issues with multiple processes
20672054 self .bring_active_window_to_front ()
2068- time .sleep (0.056 )
2055+ time .sleep (0.05 )
20692056 self .click_with_offset (selector , x_offset , y_offset )
2070- time .sleep (0.056 )
2057+ time .sleep (0.05 )
20712058 else :
20722059 self .gui_click_x_y (x , y )
20732060
0 commit comments