Skip to content

Commit

Permalink
Update UC Mode
Browse files Browse the repository at this point in the history
  • Loading branch information
mdmintz committed Aug 13, 2023
1 parent d4355ed commit 3b1643b
Showing 1 changed file with 27 additions and 12 deletions.
39 changes: 27 additions & 12 deletions seleniumbase/core/browser_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,15 +209,30 @@ def has_cf(text):

def uc_special_open_if_cf(driver, url, proxy_string=None):
if (
(url.startswith("http:") or url.startswith("https:"))
and has_cf(requests_get(url, proxy_string).text)
url.startswith("http:") or url.startswith("https:")
):
with driver:
time.sleep(0.25)
driver.execute_script('window.open("%s","_blank");' % url)
driver.close()
driver.switch_to.window(driver.window_handles[-1])
time.sleep(0.11)
special = False
try:
req_get = requests_get(url, proxy_string)
status_str = str(req_get.status_code)
if (
status_str.startswith("3")
or status_str.startswith("4")
or status_str.startswith("5")
or has_cf(req_get.text)
):
special = True
except Exception:
pass
if special:
with driver:
time.sleep(0.2)
driver.execute_script('window.open("%s","_blank");' % url)
driver.close()
driver.switch_to.window(driver.window_handles[-1])
time.sleep(0.2)
else:
driver.open(url) # The original one
else:
driver.open(url) # The original one
return None
Expand All @@ -226,9 +241,9 @@ def uc_special_open_if_cf(driver, url, proxy_string=None):
def uc_open(driver, url):
if (url.startswith("http:") or url.startswith("https:")):
with driver:
time.sleep(0.25)
time.sleep(0.2)
driver.open(url)
time.sleep(0.11)
time.sleep(0.2)
else:
driver.open(url) # The original one
return None
Expand All @@ -237,11 +252,11 @@ def uc_open(driver, url):
def uc_open_with_tab(driver, url):
if (url.startswith("http:") or url.startswith("https:")):
with driver:
time.sleep(0.25)
time.sleep(0.2)
driver.execute_script('window.open("%s","_blank");' % url)
driver.close()
driver.switch_to.window(driver.window_handles[-1])
time.sleep(0.11)
time.sleep(0.2)
else:
driver.open(url) # The original one
return None
Expand Down

0 comments on commit 3b1643b

Please sign in to comment.