Skip to content

Commit 8cf50e4

Browse files
committed
Update acceptable proxy server input format
1 parent fb8fbde commit 8cf50e4

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

seleniumbase/core/browser_launcher.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from seleniumbase.config import proxy_list
88
from seleniumbase.core import download_helper
99
from seleniumbase.fixtures import constants
10+
from seleniumbase.fixtures import page_utils
1011

1112

1213
def _set_chrome_options(downloads_path, proxy_string):
@@ -73,8 +74,8 @@ def _create_firefox_profile(downloads_path, proxy_string):
7374

7475
def display_proxy_warning(proxy_string):
7576
message = ('\n\nWARNING: 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). '
7879
'*** DEFAULTING to NOT USING a Proxy Server! ***'
7980
% proxy_string)
8081
warnings.simplefilter('always', Warning) # See Warnings
@@ -87,10 +88,24 @@ def validate_proxy_string(proxy_string):
8788
proxy_string = proxy_list.PROXY_LIST[proxy_string]
8889
if not proxy_string:
8990
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
93105
else:
106+
proxy_string = val_ip.group()
107+
valid = True
108+
if not valid:
94109
display_proxy_warning(proxy_string)
95110
proxy_string = None
96111
return proxy_string

0 commit comments

Comments
 (0)