Selenium Chrome Python with proxy how to ?

ATuringtest

Elite Member
Joined
Mar 8, 2019
Messages
1,625
Reaction score
2,848
Hi, how do you open chrome with python selenium with a proxy?
I want to shift from the vpn plugin to proxies, cant work it out :(
 
Have you checked this? I think the issue is that you use auth, and Chrome doesn't support it.
Code:
https://stackoverflow.com/questions/53082267/how-can-i-set-socks5-proxy-for-selenium-webdriver-python
 
Have you checked this? I think the issue is that you use auth, and Chrome doesn't support it.
Code:
https://stackoverflow.com/questions/53082267/how-can-i-set-socks5-proxy-for-selenium-webdriver-python

Thanks for that, but that example is for SOC5, i needed HTTP:8080
but I sorted it.

Most of the examples quote this code below

('--proxy-server=https://%s' % PROXY)

but for backend proxies it should be

('--proxy-server=' + PROXY)

Why ? Who the fuck knows
Do I care? No, it works.. move on to next bit.
 
options.add_argument("--proxy-server=socks5://127.0.0.1:1080")
This should work for selenium.

Another way to do this would be to use puppeteer. Working code below (taken from a private bot of mine):

Code:
const browser = await puppeteer.launch({
            headless: true,
            args: [
                '--no-sandbox',
                '--disable-setuid-sandbox',
                `--proxy-server=${proxy}`
            ]
        });
where proxy is host:port.
 
Typically you gotta whitelist the bot IP at the proxy server. White listed proxies work easiest, I have had difficulties myself getting proxies that require a password to work.
 
Here's an example

Python:
from selenium import webdriver

PROXY_HOST = 'proxy.example.com'
PROXY_PORT = '1234'
PROXY_USER = 'your_username'
PROXY_PASS = 'your_password'

prox = Proxy()
prox.proxy_type = ProxyType.MANUAL
prox.http_proxy = f"{PROXY_USER}:{PROXY_PASS}@{PROXY_HOST}:{PROXY_PORT}"
prox.ssl_proxy = f"{PROXY_USER}:{PROXY_PASS}@{PROXY_HOST}:{PROXY_PORT}"

capabilities = webdriver.DesiredCapabilities.CHROME
prox.add_to_capabilities(capabilities)

driver = webdriver.Chrome(desired_capabilities=capabilities)
 
Here's an example

Python:
from selenium import webdriver

PROXY_HOST = 'proxy.example.com'
PROXY_PORT = '1234'
PROXY_USER = 'your_username'
PROXY_PASS = 'your_password'

prox = Proxy()
prox.proxy_type = ProxyType.MANUAL
prox.http_proxy = f"{PROXY_USER}:{PROXY_PASS}@{PROXY_HOST}:{PROXY_PORT}"
prox.ssl_proxy = f"{PROXY_USER}:{PROXY_PASS}@{PROXY_HOST}:{PROXY_PORT}"

capabilities = webdriver.DesiredCapabilities.CHROME
prox.add_to_capabilities(capabilities)

driver = webdriver.Chrome(desired_capabilities=capabilities)

Not that I don't appreciate your shorthand Python, please stop bumping old threads.
 
Back
Top