7
7
from seleniumbase .config import proxy_list
8
8
from seleniumbase .core import download_helper
9
9
from seleniumbase .fixtures import constants
10
+ from seleniumbase .fixtures import page_utils
10
11
11
12
12
13
def _set_chrome_options (downloads_path , proxy_string ):
@@ -73,8 +74,8 @@ def _create_firefox_profile(downloads_path, proxy_string):
73
74
74
75
def display_proxy_warning (proxy_string ):
75
76
message = ('\n \n WARNING: Proxy String ["%s"] is NOT in the expected '
76
- '"ip_address:port" format, (OR the key does not exist '
77
- 'in proxy_list.PROXY_LIST). '
77
+ '"ip_address:port" or "server:port" format, '
78
+ '(OR the key does not exist in proxy_list.PROXY_LIST). '
78
79
'*** DEFAULTING to NOT USING a Proxy Server! ***'
79
80
% proxy_string )
80
81
warnings .simplefilter ('always' , Warning ) # See Warnings
@@ -87,10 +88,24 @@ def validate_proxy_string(proxy_string):
87
88
proxy_string = proxy_list .PROXY_LIST [proxy_string ]
88
89
if not proxy_string :
89
90
return None
90
- valid = re .match ('^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}:\d+$' , proxy_string )
91
- if valid :
92
- proxy_string = valid .group ()
91
+ valid = False
92
+ val_ip = re .match ('^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}:\d+$' , proxy_string )
93
+ if not val_ip :
94
+ if proxy_string .startswith ('http://' ):
95
+ proxy_string = proxy_string .split ('http://' )[1 ]
96
+ elif proxy_string .startswith ('https://' ):
97
+ proxy_string = proxy_string .split ('https://' )[1 ]
98
+ elif '://' in proxy_string :
99
+ proxy_string = proxy_string .split ('://' )[1 ]
100
+ chunks = proxy_string .split (':' )
101
+ if len (chunks ) == 2 :
102
+ if re .match ('^\d+$' , chunks [1 ]):
103
+ if page_utils .is_valid_url ('http://' + proxy_string ):
104
+ valid = True
93
105
else :
106
+ proxy_string = val_ip .group ()
107
+ valid = True
108
+ if not valid :
94
109
display_proxy_warning (proxy_string )
95
110
proxy_string = None
96
111
return proxy_string
0 commit comments