Selenium is a popular tool for automating your browsers with wide support of Open Source projects.
To establish a proxy connection via Selenium you would need to download a Selenium browser driver from the official website. Choose the browser from the list below and download the driver:
- Google Chrome
- Opera
- Firefox
Connection via login/pass authorization on Google Chrome example:
Creating a Chrome extension by including two files in an archive, named proxy.zip:
Background.js
var config = {
mode: "fixed_servers",
rules: {
singleProxy: {
scheme: "http",
host: "proxy.soax.com",
port: parseInt(9000)
},
bypassList: ["soax.com"]
}
};
chrome.proxy.settings.set({value: config, scope: "regular"}, function() {});
function callbackFn(details) {
return {
authCredentials: {
username: "PROXY_USERNAME",
password: "PROXY_PASSWORD"
}
};
}
chrome.webRequest.onAuthRequired.addListener(
callbackFn,
{urls: ["<all_urls>"]},
['blocking']
);
Manifest.json
{
"version": "1.0.0",
"manifest_version": 3,
"name": "Chrome Proxy",
"permissions": [
"Proxy",
"Tabs",
"unlimitedStorage",
"Storage",
"<all_urls>",
"webRequest",
"webRequestBlocking" ],
"background": {
"service_worker": "background.js"
},
"Minimum_chrome_version":"76.0.0"
}
The Chrome extension can be added to Selenium using the add_extension method:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_extension("proxy.zip")
driver = webdriver.Chrome(executable_path='chromedriver.exe', chrome_options=chrome_options)
driver.get("http://google.com")
driver.close()
Connecting via IP authorization
from selenium import webdriver
PROXY = "proxy.soax.com:10000"
chrome_options = WebDriver.ChromeOptions()
chrome_options.add_argument('proxy.soax.com' % PROXY) chrome = webdriver.Chrome(chrome_options=chrome_options) chrome.get("https://www.google.com")
Please feel free to reach out to support if you have any questions :)