@@ -158,7 +158,7 @@ def get_uc_driver_version():
158
158
if os .path .exists (LOCAL_UC_DRIVER ):
159
159
try :
160
160
output = subprocess .check_output (
161
- "%s --version" % LOCAL_UC_DRIVER , shell = True
161
+ ' "%s" --version' % LOCAL_UC_DRIVER , shell = True
162
162
)
163
163
if IS_WINDOWS :
164
164
output = output .decode ("latin1" )
@@ -209,15 +209,30 @@ def has_cf(text):
209
209
210
210
def uc_special_open_if_cf (driver , url , proxy_string = None ):
211
211
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:" )
214
213
):
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
221
236
else :
222
237
driver .open (url ) # The original one
223
238
return None
@@ -226,9 +241,9 @@ def uc_special_open_if_cf(driver, url, proxy_string=None):
226
241
def uc_open (driver , url ):
227
242
if (url .startswith ("http:" ) or url .startswith ("https:" )):
228
243
with driver :
229
- time .sleep (0.25 )
244
+ time .sleep (0.2 )
230
245
driver .open (url )
231
- time .sleep (0.11 )
246
+ time .sleep (0.2 )
232
247
else :
233
248
driver .open (url ) # The original one
234
249
return None
@@ -237,11 +252,11 @@ def uc_open(driver, url):
237
252
def uc_open_with_tab (driver , url ):
238
253
if (url .startswith ("http:" ) or url .startswith ("https:" )):
239
254
with driver :
240
- time .sleep (0.25 )
255
+ time .sleep (0.2 )
241
256
driver .execute_script ('window.open("%s","_blank");' % url )
242
257
driver .close ()
243
258
driver .switch_to .window (driver .window_handles [- 1 ])
244
- time .sleep (0.11 )
259
+ time .sleep (0.2 )
245
260
else :
246
261
driver .open (url ) # The original one
247
262
return None
@@ -2276,7 +2291,7 @@ def get_local_driver(
2276
2291
if os .path .exists (LOCAL_EDGEDRIVER ):
2277
2292
try :
2278
2293
output = subprocess .check_output (
2279
- "%s --version" % LOCAL_EDGEDRIVER , shell = True
2294
+ ' "%s" --version' % LOCAL_EDGEDRIVER , shell = True
2280
2295
)
2281
2296
if IS_WINDOWS :
2282
2297
output = output .decode ("latin1" )
@@ -2912,7 +2927,7 @@ def get_local_driver(
2912
2927
if os .path .exists (LOCAL_CHROMEDRIVER ):
2913
2928
try :
2914
2929
output = subprocess .check_output (
2915
- "%s --version" % LOCAL_CHROMEDRIVER , shell = True
2930
+ ' "%s" --version' % LOCAL_CHROMEDRIVER , shell = True
2916
2931
)
2917
2932
if IS_WINDOWS :
2918
2933
output = output .decode ("latin1" )
@@ -2926,7 +2941,7 @@ def get_local_driver(
2926
2941
elif path_chromedriver :
2927
2942
try :
2928
2943
output = subprocess .check_output (
2929
- "%s --version" % path_chromedriver , shell = True
2944
+ ' "%s" --version' % path_chromedriver , shell = True
2930
2945
)
2931
2946
if IS_WINDOWS :
2932
2947
output = output .decode ("latin1" )
0 commit comments