I would like to use Python to do the following: Create a local proxy which I can use with my script. Chain another proxy to the local one, so I’m actually connecting through that one. Then be able to change which proxy the local one is connecting through on the fly, so that the script will always connect to the same local proxy, but will really use a different outgoing proxy each time.
Now, excuse me if I’m using some of the wrong terms here, I don’t quite know what it’s called, but I hope you get the idea, from my poor explanation.
I’m hoping that this will be relatively simple or that there’s a python module that can help me accomplish this, but if not, please help me with some terms, so I can seek further knowledge about this.
I have a Python script using the selenium webdriver module. It allows you to automate actions on a website, like filling in forms and so on. I can set it up so the browser it uses will use a proxy to access the web. Unfortunately, I can’t change the proxy settings while the browser is running, forcing me to restart the browser every time I want to change proxy.
(my outbound proxies have login and passwod)
make the code as short as possible
dont use mitmproxy
Assistant
To achieve your goal of creating a local proxy that can chain other proxies and switch them on the fly, you can use the http.server module to create the local proxy, and requests module to handle the communication with the outbound proxies. You can manage proxy changes by updating proxy settings dynamically within your local proxy. Here’s a straightforward example:
First, let's set up a basic local proxy server using Python's built-in http.server:
With this setup, your Selenium WebDriver will always connect to the local proxy at localhost:8080, and you can change the outbound proxy dynamically without restarting the browser.