@@ -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
0 commit comments