@@ -96,16 +96,35 @@ def make_driver_executable_if_not(driver_path):
96
96
make_executable (driver_path )
97
97
98
98
99
- def requests_get (url ):
99
+ def requests_get (url , proxy_string = None ):
100
100
import requests
101
101
102
+ protocol = "http"
103
+ if proxy_string :
104
+ if proxy_string .endswith (":443" ):
105
+ protocol = "https"
106
+ elif "socks4" in proxy_string :
107
+ protocol = "socks4"
108
+ elif "socks5" in proxy_string :
109
+ protocol = "socks5"
102
110
response = None
103
- try :
104
- response = requests .get (url )
105
- except Exception :
106
- # Prevent SSLCertVerificationError / CERTIFICATE_VERIFY_FAILED
107
- url = url .replace ("https://" , "http://" )
108
- response = requests .get (url )
111
+ if proxy_string :
112
+ proxies = {protocol : proxy_string }
113
+ try :
114
+ response = requests .get (url , proxies = proxies )
115
+ except Exception :
116
+ # Prevent SSLCertVerificationError / CERTIFICATE_VERIFY_FAILED
117
+ url = url .replace ("https://" , "http://" )
118
+ time .sleep (0.04 )
119
+ response = requests .get (url , proxies = proxies )
120
+ else :
121
+ try :
122
+ response = requests .get (url )
123
+ except Exception :
124
+ # Prevent SSLCertVerificationError / CERTIFICATE_VERIFY_FAILED
125
+ url = url .replace ("https://" , "http://" )
126
+ time .sleep (0.04 )
127
+ response = requests .get (url )
109
128
return response
110
129
111
130
@@ -178,6 +197,7 @@ def find_edgedriver_version_to_use(use_version, driver_version):
178
197
def has_cf (text ):
179
198
if (
180
199
"<title>Just a moment...</title>" in text
200
+ or "<title>403 Forbidden</title>" in text
181
201
or 'id="challenge-error-text"' in text
182
202
or 'action="/?__cf_chl_f_tk' in text
183
203
or 'id="challenge-form"' in text
@@ -187,10 +207,10 @@ def has_cf(text):
187
207
return False
188
208
189
209
190
- def uc_special_open_if_cf (driver , url ):
210
+ def uc_special_open_if_cf (driver , url , proxy_string = None ):
191
211
if (
192
212
(url .startswith ("http:" ) or url .startswith ("https:" ))
193
- and has_cf (requests_get (url ).text )
213
+ and has_cf (requests_get (url , proxy_string ).text )
194
214
):
195
215
with driver :
196
216
time .sleep (0.25 )
@@ -3405,7 +3425,9 @@ def get_local_driver(
3405
3425
)
3406
3426
driver .open = driver .get # Save copy of original
3407
3427
if uc_activated :
3408
- driver .get = lambda url : uc_special_open_if_cf (driver , url )
3428
+ driver .get = lambda url : uc_special_open_if_cf (
3429
+ driver , url , proxy_string
3430
+ )
3409
3431
driver .uc_open = lambda url : uc_open (driver , url )
3410
3432
driver .uc_open_with_tab = (
3411
3433
lambda url : uc_open_with_tab (driver , url )
0 commit comments