Skip to content

Commit

Permalink
dynamic proxies now supported:)
Browse files Browse the repository at this point in the history
  • Loading branch information
kaliiiiiiiiii committed Jun 27, 2023
1 parent 60414f3 commit b9f2131
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
10 changes: 8 additions & 2 deletions src/selenium_profiles/scripts/proxy_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,14 @@ def str2val(self, url):
if "@" in url:
creds, url = url.split("@")
host, port = url.split(":")
port = int(port)
if not (scheme and host and port):
raise ValueError
values = {"host": host, "port": port, "scheme": scheme}
if creds:
username, password = creds.split(":")
if not (username and password):
raise ValueError
creds = {"password": password, "username": username}
values.update(creds)
except ValueError:
Expand All @@ -90,8 +95,9 @@ def set_single(self, proxy, bypass_list:list = ["localhost", "127.0.0.1"]):
if self._seleniumwire:
self._driver.proxy = {"http":proxy, "https":proxy, "no_proxy":",".join(bypass_list)}
elif self._injector:
raise NotImplementedError("dynamic proxies with injector not implemented yet")
#self._injector.proxy.set_single()
proxy = self.str2val(proxy)
proxy.update({"bypass_list":bypass_list})
self._injector.proxy.set_single(**proxy)

@property
def proxy(self):
Expand Down
9 changes: 5 additions & 4 deletions src/selenium_profiles/webdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,15 +200,12 @@ def __init__(self, driver, profile, cdp_handler=None, selenium_injector=None):

from selenium_interceptor.interceptor import cdp_listener
from selenium_profiles.scripts.driver_utils import requests, actions
from selenium_profiles.scripts.proxy_extension import DynamicProxy

self._driver = driver
self._profile = profile
self.injector = selenium_injector

self._seleniumwire = None
if "proxy" in self._driver.__dir__():
self._seleniumwire = True

if cdp_handler:
self.cdp_handler = cdp_handler
elif "profiles" in driver.__dir__():
Expand All @@ -222,6 +219,10 @@ def __init__(self, driver, profile, cdp_handler=None, selenium_injector=None):

requests = requests(self._driver)
self.fetch = requests.fetch
try:
self.proxy = DynamicProxy(self._driver, injector=self.injector)
except ModuleNotFoundError:
pass # not supported


# noinspection PyShadowingNames
Expand Down

0 comments on commit b9f2131

Please sign in to comment.