Skip to content

Commit 3b1643b

Browse files
committed
Update UC Mode
1 parent d4355ed commit 3b1643b

File tree

1 file changed

+27
-12
lines changed

1 file changed

+27
-12
lines changed

seleniumbase/core/browser_launcher.py

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -209,15 +209,30 @@ def has_cf(text):
209209

210210
def uc_special_open_if_cf(driver, url, proxy_string=None):
211211
if (
212-
(url.startswith("http:") or url.startswith("https:"))
213-
and has_cf(requests_get(url, proxy_string).text)
212+
url.startswith("http:") or url.startswith("https:")
214213
):
215-
with driver:
216-
time.sleep(0.25)
217-
driver.execute_script('window.open("%s","_blank");' % url)
218-
driver.close()
219-
driver.switch_to.window(driver.window_handles[-1])
220-
time.sleep(0.11)
214+
special = False
215+
try:
216+
req_get = requests_get(url, proxy_string)
217+
status_str = str(req_get.status_code)
218+
if (
219+
status_str.startswith("3")
220+
or status_str.startswith("4")
221+
or status_str.startswith("5")
222+
or has_cf(req_get.text)
223+
):
224+
special = True
225+
except Exception:
226+
pass
227+
if special:
228+
with driver:
229+
time.sleep(0.2)
230+
driver.execute_script('window.open("%s","_blank");' % url)
231+
driver.close()
232+
driver.switch_to.window(driver.window_handles[-1])
233+
time.sleep(0.2)
234+
else:
235+
driver.open(url) # The original one
221236
else:
222237
driver.open(url) # The original one
223238
return None
@@ -226,9 +241,9 @@ def uc_special_open_if_cf(driver, url, proxy_string=None):
226241
def uc_open(driver, url):
227242
if (url.startswith("http:") or url.startswith("https:")):
228243
with driver:
229-
time.sleep(0.25)
244+
time.sleep(0.2)
230245
driver.open(url)
231-
time.sleep(0.11)
246+
time.sleep(0.2)
232247
else:
233248
driver.open(url) # The original one
234249
return None
@@ -237,11 +252,11 @@ def uc_open(driver, url):
237252
def uc_open_with_tab(driver, url):
238253
if (url.startswith("http:") or url.startswith("https:")):
239254
with driver:
240-
time.sleep(0.25)
255+
time.sleep(0.2)
241256
driver.execute_script('window.open("%s","_blank");' % url)
242257
driver.close()
243258
driver.switch_to.window(driver.window_handles[-1])
244-
time.sleep(0.11)
259+
time.sleep(0.2)
245260
else:
246261
driver.open(url) # The original one
247262
return None

0 commit comments

Comments
 (0)