@@ -158,7 +158,7 @@ def get_uc_driver_version():
158158 if os .path .exists (LOCAL_UC_DRIVER ):
159159 try :
160160 output = subprocess .check_output (
161- "%s --version" % LOCAL_UC_DRIVER , shell = True
161+ ' "%s" --version' % LOCAL_UC_DRIVER , shell = True
162162 )
163163 if IS_WINDOWS :
164164 output = output .decode ("latin1" )
@@ -209,15 +209,30 @@ def has_cf(text):
209209
210210def 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):
226241def 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):
237252def 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
@@ -2276,7 +2291,7 @@ def get_local_driver(
22762291 if os .path .exists (LOCAL_EDGEDRIVER ):
22772292 try :
22782293 output = subprocess .check_output (
2279- "%s --version" % LOCAL_EDGEDRIVER , shell = True
2294+ ' "%s" --version' % LOCAL_EDGEDRIVER , shell = True
22802295 )
22812296 if IS_WINDOWS :
22822297 output = output .decode ("latin1" )
@@ -2912,7 +2927,7 @@ def get_local_driver(
29122927 if os .path .exists (LOCAL_CHROMEDRIVER ):
29132928 try :
29142929 output = subprocess .check_output (
2915- "%s --version" % LOCAL_CHROMEDRIVER , shell = True
2930+ ' "%s" --version' % LOCAL_CHROMEDRIVER , shell = True
29162931 )
29172932 if IS_WINDOWS :
29182933 output = output .decode ("latin1" )
@@ -2926,7 +2941,7 @@ def get_local_driver(
29262941 elif path_chromedriver :
29272942 try :
29282943 output = subprocess .check_output (
2929- "%s --version" % path_chromedriver , shell = True
2944+ ' "%s" --version' % path_chromedriver , shell = True
29302945 )
29312946 if IS_WINDOWS :
29322947 output = output .decode ("latin1" )
0 commit comments